### Install Dependencies Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Installs project dependencies using npm or pnpm. This is the first step before running the server or examples. ```bash npm install # 或者使用pnpm pnpm install ``` -------------------------------- ### Start Server Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Starts the Swagger MCP server using Node.js. The server communicates via standard input/output by default. ```bash node start-server.js ``` -------------------------------- ### Generate React Query Client Example Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Example of generating an API client specifically for React Query, demonstrating the `clientType` parameter and other common options. ```APIDOC { "method": "generate-api-client-optimized", "params": { "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json", "outputDir": "./generated/react-query", "clientType": "react-query", "generateTypeImports": true } } ``` -------------------------------- ### MCP Tool Examples Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Demonstrates how to use MCP tools for common tasks like parsing Swagger documents, generating TypeScript types, and creating API client code. ```bash # 解析Swagger文档 node examples/optimized-swagger-parser-example.js # 生成TypeScript类型 node examples/typescript-generator-example.js # 生成API客户端 node examples/api-client-generator-example.js ``` -------------------------------- ### Configuration File Example Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Shows the structure of the `swagger-mcp-config.json` file used to customize server settings like name, version, and transport protocol. ```json { "name": "Swagger MCP Server", "version": "1.0.0", "transport": "stdio" } ``` -------------------------------- ### Development Debugging Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Commands for starting the server in debug mode and connecting with the MCP Inspector for development and debugging purposes. ```bash node start-server.js npx @modelcontextprotocol/inspector pipe -- node start-server.js # 或者直接方式(但可能导致输出混乱) npx @modelcontextprotocol/inspector -- node start-server.js ``` -------------------------------- ### Large Document Processing Example Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Example configuration for processing large API documents efficiently using the lite parser with caching, lazy loading, and tag filtering. ```APIDOC { "method": "parse-swagger-lite", "params": { "url": "https://your-large-api-doc-url.json", "useCache": true, "skipValidation": true, "lazyLoading": true, "filterTag": "your-specific-tag", "includeSchemas": false } } ``` -------------------------------- ### 多语言客户端生成支持 Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 项目计划支持生成多种编程语言的API客户端,包括Python、Java和Go,以满足不同项目需求。 ```APIDOC MCP Tool: Multi-Language Client Generator Functionality: - Generates API client code for various programming languages. - Currently planned support for Python, Java, and Go. - Leverages parsed API specifications to create language-idiomatic clients. Usage Example (Conceptual): mcp generate client --input-spec api_spec.json --language python --output-dir ./python-client mcp generate client --input-spec api_spec.json --language java --output-dir ./java-client mcp generate client --input-spec api_spec.json --language go --output-dir ./go-client Parameters: --input-spec (string, required): Path to the parsed API specification. --language (string, required): Target programming language (python, java, go). --output-dir (string, required): Directory to save the generated client code. Output: Generates client code files specific to the target language. ``` -------------------------------- ### MCP 工具 - Swagger 解析 Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 实现一个MCP工具,用于解析Swagger/OpenAPI文档。该工具支持不同版本的OpenAPI规范,并提供参数过滤功能,优化返回结果格式。 ```APIDOC MCP Tool: Swagger Parser Functionality: - Parses Swagger/OpenAPI specifications from a given URL or file. - Supports OpenAPI versions 2.0 and 3.x. - Allows filtering API operations by tags, paths, or other criteria. - Optimizes the output format for downstream processing. Usage Example: mcp parse swagger --url http://petstore.swagger.io/v2/swagger.json --filter-tag pet --output-format json Parameters: --url (string, required): URL or path to the Swagger/OpenAPI document. --filter-tag (string, optional): Comma-separated list of tags to include. --filter-path (string, optional): Comma-separated list of paths to include. --output-format (string, optional): Desired output format (e.g., json, yaml). Defaults to json. Error Handling: - Handles invalid URLs or file paths. - Reports parsing errors for malformed OpenAPI documents. - Provides feedback on unsupported OpenAPI versions. ``` -------------------------------- ### MCP 工具 - API 客户端生成 Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 实现一个MCP工具,用于生成API客户端代码。支持多种框架(Axios, Fetch, React Query),提供性能优化选项(缓存, 懒加载),并包含进度反馈机制。 ```APIDOC MCP Tool: API Client Generator Functionality: - Generates API client code based on parsed API specifications. - Supports multiple frameworks: Axios, Fetch, React Query. - Incorporates performance optimizations like caching and lazy loading. - Provides progress feedback during generation. Usage Example: mcp generate client --input-spec api_spec.json --framework react-query --output-dir ./api-client --progress Parameters: --input-spec (string, required): Path to the parsed API specification. --framework (string, required): Target framework (axios, fetch, react-query). --output-dir (string, required): Directory to save the generated client code. --cache (boolean, optional): Enable caching for generated client code. --lazy-load (boolean, optional): Enable lazy loading for client modules. --progress (boolean, optional): Display progress during generation. --template (string, optional): Path to a custom code generation template. Output: Generates client code files (e.g., .ts, .js) in the specified output directory. ``` -------------------------------- ### API 接口代码生成器 (Axios/Fetch) Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 实现一个API接口代码生成器,能够根据API操作定义生成函数,支持多种框架如Axios和Fetch。此工具旨在简化API客户端的开发。 ```JavaScript // 示例:使用Axios生成API请求函数 // 假设Swagger定义了 /users GET 方法 // import axios from 'axios'; /** * 获取用户列表 * @returns {Promise>} 用户列表 */ // async function getUsers() { // try { // const response = await axios.get('/users'); // return response.data; // } catch (error) { // console.error('Error fetching users:', error); // throw error; // } // } // 示例:使用Fetch API生成 /** * 获取用户列表 (Fetch API) * @returns {Promise>} 用户列表 */ // async function getUsersFetch() { // try { // const response = await fetch('/users'); // if (!response.ok) { // throw new Error(`HTTP error! status: ${response.status}`); // } // return await response.json(); // } catch (error) { // console.error('Error fetching users:', error); // throw error; // } // } ``` -------------------------------- ### MCP 工具 - TypeScript 类型生成 Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 实现一个MCP工具,用于生成TypeScript类型定义。该工具集成类型生成器,支持缓存、懒加载和模式解析策略,并提供过滤和自定义选项。 ```APIDOC MCP Tool: TypeScript Type Generator Functionality: - Generates TypeScript type definitions from parsed API specifications. - Integrates with the core TypeScript type generator. - Supports caching and lazy loading for performance optimization. - Allows customization of type generation strategies and filtering. Usage Example: mcp generate types --input-spec swagger.json --output-file types.ts --cache --lazy-load --strategy advanced Parameters: --input-spec (string, required): Path to the parsed API specification (e.g., JSON output from parser). --output-file (string, required): Path to save the generated TypeScript file. --cache (boolean, optional): Enable caching for generated types. --lazy-load (boolean, optional): Enable lazy loading for large schemas. --strategy (string, optional): Type generation strategy (e.g., basic, advanced, custom). --filter-schema (string, optional): JSONPath or similar to filter specific schema parts. Output: Generates a .ts file containing TypeScript interfaces and types. ``` -------------------------------- ### TypeScript 类型定义生成器 Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/road.md 实现一个TypeScript类型定义生成器,用于分析Swagger模式定义,并将其转换为对应的TypeScript接口或类型。此功能是MCP服务器的核心部分,用于提供强类型约束。 ```TypeScript /** * 分析Swagger模式定义并生成TypeScript类型。 * 例如: * Swagger Schema: { * "type": "object", * "properties": { * "name": {"type": "string"}, * "age": {"type": "integer"} * } * } * * 生成的TypeScript类型: * interface User { * name?: string; * age?: number; * } */ // 核心逻辑将在此实现,包括模式分析和类型映射。 ``` -------------------------------- ### API Client Generation Tools Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Provides MCP methods for generating API client code for various frameworks like Axios, Fetch, and React Query. Allows customization of output, type imports, and grouping strategies. ```APIDOC Standard API Client Generator (generate-api-client): { "method": "generate-api-client", "params": { "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json", "outputDir": "./generated/api", "clientType": "axios", "generateTypeImports": true, "typesImportPath": "../types", "groupBy": "tag" } } Optimized API Client Generator (generate-api-client-optimized): { "method": "generate-api-client-optimized", "params": { "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json", "outputDir": "./generated/api", "clientType": "react-query", "generateTypeImports": true, "typesImportPath": "../types", "groupBy": "tag", "useCache": true, "skipValidation": true, "lazyLoading": true, "includeTags": ["pet", "store"] } } ``` -------------------------------- ### File Writer Tool Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md A utility MCP method for writing content to a specified file path. Supports creating directories if they do not exist. ```APIDOC { "method": "file-writer", "params": { "filePath": "./output.txt", "content": "Hello, world!", "createDirs": true } } ``` -------------------------------- ### Swagger/OpenAPI Parsing Tools Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Provides MCP methods for parsing Swagger/OpenAPI documents. Includes standard, optimized, and lite versions with options for caching, validation, and schema inclusion. ```APIDOC Standard Parsing Tool (parse-swagger): { "method": "parse-swagger", "params": { "url": "https://petstore3.swagger.io/api/v3/openapi.json", "includeSchemas": true, "includeDetails": true } } Optimized Parsing Tool (parse-swagger-optimized): { "method": "parse-swagger-optimized", "params": { "url": "https://petstore3.swagger.io/api/v3/openapi.json", "includeSchemas": true, "includeDetails": true, "useCache": true, "skipValidation": true, "cacheTTLMinutes": 60, "lazyLoading": false, "filterTag": "pet" } } Lite Parsing Tool (parse-swagger-lite): { "method": "parse-swagger-lite", "params": { "url": "https://petstore3.swagger.io/api/v3/openapi.json", "includeSchemas": false, "includeDetails": false, "useCache": true, "skipValidation": true } } ``` -------------------------------- ### TypeScript Type Generation Tools Source: https://github.com/tuskermanshu/swagger-mcp-server/blob/master/README.md Offers MCP methods for generating TypeScript type definitions from Swagger/OpenAPI specifications. Supports standard and optimized generation with options for output directory, namespaces, and strict types. ```APIDOC Standard Type Generator (generate-typescript-types): { "method": "generate-typescript-types", "params": { "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json", "outputDir": "./generated/types", "namespace": "PetStore", "strictTypes": true, "generateEnums": true, "generateIndex": true } } Optimized Type Generator (generate-typescript-types-optimized): { "method": "generate-typescript-types-optimized", "params": { "swaggerUrl": "https://petstore3.swagger.io/api/v3/openapi.json", "outputDir": "./generated/types", "namespace": "PetStore", "strictTypes": true, "useCache": true, "skipValidation": true, "lazyLoading": true, "includeSchemas": ["Pet", "Order", "User"] } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.