swaggertomcp
🔁 Convert Swagger/OpenAPI specs into Model Context Protocol (MCP) tool definitions for agentic AI compatibility.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.9%) to scientific vocabulary
Keywords
Repository
🔁 Convert Swagger/OpenAPI specs into Model Context Protocol (MCP) tool definitions for agentic AI compatibility.
Basic Info
Statistics
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
SwaggerToMCP
A CLI tool that converts Swagger/OpenAPI JSON files into Anthropic's Model Context Protocol (MCP) format. Now with full OpenAPI 3.1.0 support!
Project Summary: SwaggerToMCP bridges the gap between OpenAPI specifications and Anthropic's Claude AI by transforming API definitions into the MCP format. This enables seamless integration of external APIs with Claude, allowing the AI to interact with these services through well-defined tool interfaces.
Quick Overview
SwaggerToMCP is a command-line tool that takes a Swagger/OpenAPI JSON file as input and converts it to a valid MCPContext JSON file. The tool preserves all metadata from the OpenAPI input and outputs in compliance with Anthropic's Model Context Protocol (MCP) schema.
Key Features
- Converts OpenAPI operations to MCP Tool objects
- Preserves all metadata from the OpenAPI specification
- Maps OpenAPI fields to their corresponding MCP fields
- Outputs a JSON file compliant with MCP's Tool schema
- Handles complex parameter structures and nested schemas
- Supports OpenAPI 2.0 (Swagger), 3.0, and 3.1.0 specifications
- Full OpenAPI 3.1.0 schema support:
- Type arrays (e.g.,
["string", "null"]) for nullable fields - Schema composition with
oneOf,anyOf, andallOf - Discriminator mapping for polymorphic schemas
- References (
$ref) alongside other properties
- Type arrays (e.g.,
- Maintains security definitions and requirements
- Provides detailed error reporting for invalid specifications
Installation
```bash
Clone the repository
git clone https://github.com/grparry/SwaggerToMCP.git cd SwaggerToMCP
Build the project
dotnet build ```
Usage Example
```bash
Convert a Swagger/OpenAPI file to MCP format
dotnet run --project SwaggerToMCP.Cli -- -i ./path/to/swagger.json -o ./output/mcp-context.json
Or with full argument names
dotnet run --project SwaggerToMCP.Cli -- --input ./path/to/swagger.json --output ./output/mcp-context.json ```
Contributing
Contributions are welcome! Please see our CONTRIBUTING.md file for detailed guidelines on how to contribute to this project.
If you'd like to improve SwaggerToMCP, please feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your code follows the existing style and includes appropriate tests.
Documentation
For detailed documentation, advanced usage examples, and technical details, please see the detailed README in the SwaggerToMCP directory.
OpenAPI 3.1.0 Support
SwaggerToMCP now fully supports OpenAPI 3.1.0, which brings several significant improvements over OpenAPI 3.0:
Key OpenAPI 3.1.0 Features Supported
JSON Schema Alignment
- SwaggerToMCP now correctly parses OpenAPI 3.1.0 documents aligned with JSON Schema 2020-12
- Support for
typearrays (e.g.,["string", "null"]) for nullable types
Enhanced Schema Composition
- Full support for
oneOf,anyOf, andallOfschema compositions - Proper discriminator handling for polymorphic schemas
- Full support for
Extended References
- Support for
$refalongside other keywords - This enables more flexible schema definitions and extensions
- Support for
Improved Nullable Handling
- Correctly processes both OpenAPI 3.0.x
nullable: trueand OpenAPI 3.1.0 type arrays - Ensures consistent representation in MCP format
- Correctly processes both OpenAPI 3.0.x
These features are automatically detected when parsing OpenAPI documents, with no additional configuration required.
Examples
Check out the examples directory for sample Swagger/OpenAPI files and their corresponding MCP outputs. These examples demonstrate how to use the tool with different API specifications and how to integrate the generated MCP files with Claude.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this software in your research or projects, please cite it using the information in the CITATION.cff file.
Owner
- Login: grparry
- Kind: user
- Repositories: 1
- Profile: https://github.com/grparry
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Parry"
given-names: "Grant"
title: "SwaggerToMCP"
version: 1.0.0
date-released: 2025-04-22
url: "https://github.com/grparry/SwaggerToMCP"
repository-code: "https://github.com/grparry/SwaggerToMCP"
license: MIT
type: software
description: "A CLI tool that converts Swagger/OpenAPI JSON files into Anthropic's Model Context Protocol (MCP) format."
keywords:
- swagger
- openapi
- mcp
- anthropic
- claude
- api
- conversion
- tool
GitHub Events
Total
- Watch event: 1
- Push event: 9
- Fork event: 1
- Create event: 2
Last Year
- Watch event: 1
- Push event: 9
- Fork event: 1
- Create event: 2
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- Microsoft.OpenApi.Readers 1.6.13
- Newtonsoft.Json 13.0.3
- System.CommandLine 2.0.0-beta4.22272.1
- Microsoft.NET.Test.Sdk 17.8.0
- coverlet.collector 6.0.0
- xunit 2.6.1
- xunit.runner.visualstudio 2.5.3