Skip to main content
Glama
README.md
# Swagger JSON MCP Server

[![TypeScript](https://img.shields.io/badge/TypeScript-5.8.3-blue.svg)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/Node.js->=18.0.0-green.svg)](https://nodejs.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Model Context Protocol](https://img.shields.io/badge/MCP-1.16.0-purple.svg)](https://modelcontextprotocol.io/)

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 projects
- `get_swagger_overview`: Get project overview and statistics
- `get_api_info`: Retrieve complete API information with resolved schemas
- `get_schema`: Get fully resolved schema definitions
- `search_apis`: Search API endpoints with advanced filtering
- `search_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
```bash
# 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
```bash
# Development mode
pnpm dev

# Production mode
pnpm start
```

### 3. Configure MCP Client
Add to your MCP client configuration:

```json
{
  "mcpServers": {
    "swagger-json": {
      "command": "node",
      "args": ["path/to/swagger-json-mcp/dist/index.js"],
      "env": {}
    }
  }
}
```

## ๐Ÿ“– Usage Examples

### List Available Projects
```typescript
// 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
```typescript
// 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
```typescript
// 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
```typescript
// 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
```bash
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
```bash
# 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 `$ref` references
- 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
```bash
# 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.ts` for custom logging
- Extend `src/core/SwaggerManager.ts` for additional project types
- Add new MCP tools in `src/mcp/tools/`

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-feature`
3. Make your changes with tests
4. Run the test suite: `pnpm test`
5. Ensure code quality: `pnpm lint && pnpm typecheck`
6. Commit changes: `git commit -m 'Add new feature'`
7. Push to branch: `git push origin feature/new-feature`
8. 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](LICENSE) file for details.

## ๐Ÿ†˜ Troubleshooting

### Common Issues

**Project not loading**
- Verify `docs/` directory structure
- Check `swagger.json` file 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:
```bash
LOG_LEVEL=debug pnpm start
```

## ๐ŸŒŸ Acknowledgments

- [Model Context Protocol](https://modelcontextprotocol.io/) - Protocol specification
- [OpenAPI Specification](https://swagger.io/specification/) - API documentation standard
- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript
- [Vitest](https://vitest.dev/) - Fast testing framework

---

Made with โค๏ธ for better API documentation accessibility

TDQS

A3.8/5.0

Scored across 6 tools

Disambiguation5/5

Each tool targets a distinct resource and action: listing swaggers, getting overviews, retrieving schemas, retrieving API info, and searching APIs or schemas. No overlap in purpose; agents can easily select the right tool.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern using snake_case (list_*, get_*, search_*). The nouns are clear and descriptive, with only minor pluralization inconsistencies that do not affect predictability.

Tool Count5/5

Six tools is well-scoped for a Swagger/OpenAPI inspection server. Each tool covers a distinct aspect of reading and exploring API definitions without being excessive or minimal.

Completeness5/5

The tool surface provides a complete read-only workflow: list available Swagger files, get overview statistics, retrieve detailed schema definitions with $ref resolution, get full API info, and search for APIs/schemas. No obvious gaps for a browsing/inspection use case.

Maintenance

ActivityInactive
ResponsivenessNo issues