swagger-json-mcp
A powerful MCP server for querying and processing large Swagger/OpenAPI JSON documents, enabling LLMs to efficiently access API documentation without loading entire files.
README
Swagger JSON MCP Server
A powerful Model Context Protocol (MCP) server designed to efficiently query and process large Swagger/OpenAPI JSON documents. This server solves the common problem of LLMs being unable to process large API documentation files (typically 4000+ lines) by providing structured, intelligent query interfaces.
🚀 Features
Core Capabilities
- 📋 Multi-project Management: Seamlessly handle multiple Swagger/OpenAPI projects
- 🔍 Smart $ref Resolution: Automatically resolve JSON Schema references and handle circular dependencies
- 🔎 Intelligent Search: Advanced search capabilities for APIs and schemas with fuzzy matching
- ⚡ Efficient Querying: Get specific API or schema information without loading entire documents
- 🔄 Real-time Updates: Automatically detect and reload changes in Swagger files
MCP Tools
list_swaggers: List all available Swagger projectsget_swagger_overview: Get project overview and statisticsget_api_info: Retrieve complete API information with resolved schemasget_schema: Get fully resolved schema definitionssearch_apis: Search API endpoints with advanced filteringsearch_schemas: Search schema definitions with type filtering
📁 Project Structure
swagger-json-mcp/
├── src/
│ ├── core/ # Core functionality modules
│ │ ├── SwaggerParser.ts # Swagger JSON parser
│ │ ├── SchemaResolver.ts # $ref reference resolver
│ │ └── SwaggerManager.ts # Multi-project manager
│ ├── mcp/ # MCP server implementation
│ │ ├── tools/ # MCP tool definitions
│ │ └── types.ts # TypeScript type definitions
│ ├── utils/ # Utility functions
│ └── index.ts # Main entry point
├── docs/ # Swagger documentation directory
│ └── [project-name]/ # Individual project folders
│ └── swagger.json # Swagger/OpenAPI JSON files
├── package.json
├── tsconfig.json
└── README.md
🛠️ Installation
Prerequisites
- Node.js >= 18.0.0
- pnpm >= 8.0.0
Setup
# Clone the repository
git clone <repository-url>
cd swagger-json-mcp
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run tests
pnpm test
🚀 Quick Start
1. Prepare Your Swagger Files
Create project directories under docs/ and place your swagger.json files:
docs/
├── your-api-project/
│ └── swagger.json
└── another-project/
└── swagger.json
2. Start the MCP Server
# Development mode
pnpm dev
# Production mode
pnpm start
3. Configure MCP Client
Add to your MCP client configuration:
{
"mcpServers": {
"swagger-json": {
"command": "node",
"args": ["path/to/swagger-json-mcp/dist/index.js"],
"env": {}
}
}
}
📖 Usage Examples
List Available Projects
// MCP Tool Call
{
"name": "list_swaggers",
"arguments": {}
}
// Response
{
"projects": [
{
"name": "your-api-project",
"title": "Your API",
"version": "1.0.0",
"apiCount": 42,
"schemaCount": 28
}
]
}
Get API Information
// MCP Tool Call
{
"name": "get_api_info",
"arguments": {
"swaggerName": "your-api-project",
"path": "/api/users",
"method": "post"
}
}
// Response includes fully resolved schemas
{
"path": "/api/users",
"method": "post",
"summary": "Create user",
"requestBody": {
// Fully resolved schema without $ref
},
"responses": {
// Fully resolved response schemas
}
}
Search APIs
// MCP Tool Call
{
"name": "search_apis",
"arguments": {
"query": "user login",
"swaggerName": "your-api-project",
"method": "post"
}
}
// Response
{
"results": [
{
"path": "/auth/login",
"method": "post",
"summary": "User login",
"score": 0.95
}
]
}
Resolve Complex Schemas
// MCP Tool Call
{
"name": "get_schema",
"arguments": {
"swaggerName": "your-api-project",
"schemaName": "UserProfile",
"maxDepth": 10
}
}
// Response includes all nested schemas resolved
{
"schema": {
"type": "object",
"properties": {
// All $ref references resolved recursively
}
},
"dependencies": ["Address", "ContactInfo"],
"circularReferences": []
}
🧪 Development
Available Scripts
pnpm build # Compile TypeScript
pnpm dev # Development with hot reload
pnpm test # Run test suite
pnpm lint # Run ESLint
pnpm typecheck # TypeScript type checking
pnpm prettier # Format code
pnpm clean # Clean build directory
Code Quality
- TypeScript: Strict mode enabled with comprehensive type definitions
- ESLint: Configured with TypeScript and Prettier rules
- Vitest: Fast unit testing with full coverage
- Prettier: Consistent code formatting
Testing
# Run all tests
pnpm test
# Run tests in watch mode
pnpm test --watch
# Run tests with coverage
pnpm test --coverage
🏗️ Architecture
Core Components
SwaggerParser
- Validates and parses Swagger/OpenAPI JSON files
- Handles multiple OpenAPI versions (2.0, 3.0.x)
- Provides structured access to API definitions
SchemaResolver
- Recursively resolves
$refreferences - Detects and handles circular dependencies
- Configurable resolution depth
- Caches resolved schemas for performance
SwaggerManager
- Manages multiple Swagger projects
- Automatic file discovery and loading
- Project lifecycle management
- Thread-safe operations
MCP Integration
- Full compliance with Model Context Protocol specification
- Structured tool definitions with comprehensive validation
- Error handling and logging
- Async/await throughout for optimal performance
🔧 Configuration
Environment Variables
# Optional: Set log level
LOG_LEVEL=info
# Optional: Custom docs directory
DOCS_DIR=./custom-docs
# Optional: Maximum schema resolution depth
MAX_SCHEMA_DEPTH=10
Customization
- Modify
src/utils/logger.tsfor custom logging - Extend
src/core/SwaggerManager.tsfor additional project types - Add new MCP tools in
src/mcp/tools/
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make your changes with tests
- Run the test suite:
pnpm test - Ensure code quality:
pnpm lint && pnpm typecheck - Commit changes:
git commit -m 'Add new feature' - Push to branch:
git push origin feature/new-feature - Submit a pull request
Development Guidelines
- Follow existing code style and conventions
- Add tests for new functionality
- Update documentation for API changes
- Ensure TypeScript compliance
- Write clear, descriptive commit messages
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🆘 Troubleshooting
Common Issues
Project not loading
- Verify
docs/directory structure - Check
swagger.jsonfile validity - Ensure proper JSON formatting
$ref resolution failing
- Validate JSON Schema reference paths
- Check for circular references
- Verify component definitions exist
MCP connection issues
- Confirm server startup success
- Validate MCP client configuration
- Check Node.js version compatibility
Debug Mode
Enable detailed logging:
LOG_LEVEL=debug pnpm start
🌟 Acknowledgments
- Model Context Protocol - Protocol specification
- OpenAPI Specification - API documentation standard
- TypeScript - Type-safe JavaScript
- Vitest - Fast testing framework
Made with ❤️ for better API documentation accessibility
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。