get_swagger_documentation
Fetch the full Swagger/OpenAPI specification to explore and understand all REST API endpoints.
Instructions
Get the complete Swagger/OpenAPI documentation for available endpoints
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:327-343 (handler)The handler method in the McpRestServer class that executes the tool logic. It checks that the REST client is configured, then calls this.restClient.getSwaggerDocumentation() and returns the result as tool output.
private async getSwaggerDocumentation() { if (!this.restClient) { throw new Error( "REST client not configured. Use configure_rest_client tool or provide configuration via CLI/environment variables." ); } const documentation = this.restClient.getSwaggerDocumentation(); return { content: [ { type: "text", text: documentation, }, ], }; } - src/index.ts:48-218 (registration)The tool registration in the ListToolsRequestSchema handler. Defines the tool name 'get_swagger_documentation', its description, and empty inputSchema (no params required).
private setupHandlers(): void { this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "configure_rest_client", description: "Configure the REST client with base URL, authentication, and optional Swagger documentation URL", inputSchema: { type: "object", properties: { baseUrl: { type: "string", description: "Base URL for the REST API", }, swaggerUrl: { type: "string", description: "URL to Swagger/OpenAPI documentation (optional)", }, auth: { type: "object", oneOf: [ { type: "object", properties: { type: { type: "string", enum: ["token"] }, token: { type: "string", description: "Authentication token", }, }, required: ["type", "token"], }, { type: "object", properties: { type: { type: "string", enum: ["login"] }, username: { type: "string", description: "Username for login", }, password: { type: "string", description: "Password for login", }, loginEndpoint: { type: "string", description: "Login endpoint path", }, tokenField: { type: "string", description: "Field name for access token in response (default: access_token)", }, }, required: [ "type", "username", "password", "loginEndpoint", ], }, ], }, timeout: { type: "number", description: "Request timeout in milliseconds (default: 30000)", }, retries: { type: "number", description: "Number of retries for failed requests (default: 3)", }, }, required: ["baseUrl", "auth"], }, }, { name: "http_request", description: "Make an HTTP request to the configured API", inputSchema: { type: "object", properties: { method: { type: "string", enum: ["GET", "POST", "PUT", "DELETE", "PATCH"], description: "HTTP method", }, path: { type: "string", description: "API endpoint path", }, params: { type: "object", description: "Query parameters (for GET) or request body parameters", }, body: { type: "object", description: "Request body (for POST, PUT, PATCH)", }, headers: { type: "object", description: "Additional headers", }, }, required: ["method", "path"], }, }, { name: "get_swagger_documentation", description: "Get the complete Swagger/OpenAPI documentation for available endpoints", inputSchema: { type: "object", properties: {}, }, }, { name: "search_endpoints", description: "Search for endpoints in the Swagger documentation", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query to find matching endpoints", }, }, required: ["query"], }, }, { name: "get_endpoint_info", description: "Get detailed information about a specific endpoint", inputSchema: { type: "object", properties: { path: { type: "string", description: "Endpoint path", }, method: { type: "string", description: "HTTP method", }, }, required: ["path", "method"], }, }, { name: "check_authentication", description: "Check if the client is currently authenticated", inputSchema: { type: "object", properties: {}, }, }, { name: "logout", description: "Logout and clear authentication state", inputSchema: { type: "object", properties: {}, }, }, ] as Tool[], }; }); - src/index.ts:220-262 (registration)The CallToolRequestSchema handler that routes the tool call to the getSwaggerDocumentation method when name matches 'get_swagger_documentation'.
this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case "configure_rest_client": return await this.configureRestClient(args); case "http_request": return await this.makeHttpRequest(args); case "get_swagger_documentation": return await this.getSwaggerDocumentation(); case "search_endpoints": return await this.searchEndpoints(args); case "get_endpoint_info": return await this.getEndpointInfo(args); case "check_authentication": return await this.checkAuthentication(); case "logout": return await this.logout(); default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], isError: true, }; } }); - src/rest-client.ts:176-181 (helper)The RestClient.getSwaggerDocumentation() helper method that delegates to SwaggerDocumentationParser.getEndpointSummary(). Returns a formatted string of all available endpoints or a message if Swagger is not configured.
getSwaggerDocumentation(): string { if (!this.swaggerParser) { return "Swagger documentation not configured"; } return this.swaggerParser.getEndpointSummary(); } - src/swagger.ts:150-165 (helper)The SwaggerDocumentationParser.getEndpointSummary() method that formats all parsed endpoints into a human-readable summary string listing method, path, and optional summary for each endpoint.
getEndpointSummary(): string { if (!this.parsed) { return "Documentation not loaded"; } const summary = this.endpoints .map( (endpoint) => `${endpoint.method} ${endpoint.path}${ endpoint.summary ? ` - ${endpoint.summary}` : "" }` ) .join("\n"); return `Available endpoints (${this.endpoints.length}):\n${summary}`; }