build static method

Map<String, dynamic> build(
  1. List<Map<String, dynamic>> tools,
  2. String transport,
  3. int port,
  4. String address,
)

Generates an OpenAPI 3.0 specification from tool definitions.

tools - List of tool definitions with parameters and metadata transport - Transport protocol (http or stdio) port - Server port number address - Server bind address

Returns a Map representing the complete OpenAPI 3.0 specification.

Implementation

static Map<String, dynamic> build(
  List<Map<String, dynamic>> tools,
  String transport,
  int port,
  String address,
) {
  // Group tools by inferred resource
  final resourceGroups = _groupToolsByResource(tools);

  // Build RESTful paths
  final paths = _buildRestfulPaths(resourceGroups);

  // Build complete OpenAPI specification
  return <String, dynamic>{
    'openapi': '3.0.3',
    'info': <String, dynamic>{
      'title': 'API Documentation',
      'version': '1.0.0',
      'description': 'Auto-generated OpenAPI specification from MCP tools',
    },
    'servers': [
      <String, dynamic>{
        'url': transport == 'http'
            ? 'http://$address:$port'
            : 'http://localhost:3000',
        'description': transport == 'http'
            ? 'HTTP API Server'
            : 'Local API Server',
      },
    ],
    'paths': paths,
  };
}