OpenApiToOcelot.Cli
0.1.5
dotnet tool install --global OpenApiToOcelot.Cli --version 0.1.5
dotnet new tool-manifest
dotnet tool install --local OpenApiToOcelot.Cli --version 0.1.5
#tool dotnet:?package=OpenApiToOcelot.Cli&version=0.1.5
nuke :add-package OpenApiToOcelot.Cli --version 0.1.5
OpenAPISpecMCP
Generates Ocelot API-gateway configuration (ocelot.json) from an OpenAPI 2.0 or 3.x specification. Ships in three shapes:
| Package | What it is |
|---|---|
OpenApiToOcelot.Core |
Pure conversion library. No MCP, no CLI dependencies. |
OpenApiToOcelot.Cli |
dotnet tool (openapi-to-ocelot) with generate, preview, validate, extensions subcommands. |
OpenApiToOcelot.Mcp |
Model Context Protocol server (stdio). Exposes the same operations as tools to AI clients. |
The converter covers the full Ocelot route surface — AuthenticationOptions, RateLimitOptions, QoSOptions, FileCacheOptions, LoadBalancerOptions, SecurityOptions, HttpHandlerOptions, ServiceDiscoveryProvider, header/claim/query transforms, delegating handlers, priorities, keys. Anything not derivable from standard OpenAPI is opted-in via x-ocelot-* vendor extensions.
Quick start (CLI)
# Pack and install the tool locally
dotnet pack src/OpenApiToOcelot.Cli -c Release -o ./nupkg
dotnet tool install --global --add-source ./nupkg OpenApiToOcelot.Cli
# Generate ocelot.json from a Petstore spec
openapi-to-ocelot generate petstore.yaml -o ocelot.json
# Preview the routes table (no JSON output)
openapi-to-ocelot preview petstore.yaml
# List supported x-ocelot-* extensions
openapi-to-ocelot extensions
Command reference
openapi-to-ocelot generate <spec> [options]
-o, --output FILE Write ocelot.json to this file (default: stdout)
--downstream-scheme SCHEME Override scheme (http|https)
--downstream-host HOST:PORT Override downstream target (repeatable)
--base-url URL GlobalConfiguration.BaseUrl
--upstream-prefix PREFIX Prepend to every UpstreamPathTemplate
--strip-prefix PREFIX Strip from DownstreamPathTemplate
--upstream-host HOST Set Route.UpstreamHost (host filter)
--no-auth Skip AuthenticationOptions on every route
--split-methods Emit a separate route per HTTP method (default: one route per path)
--swagger-key KEY MMLib.SwaggerForOcelot: SwaggerKey on every route + matching SwaggerEndPoints entry
--swagger-url URL Downstream swagger.json URL (paired with --swagger-key)
--swagger-name NAME Display name (defaults to info.title)
--swagger-version VER Version label (defaults to info.version)
Quick start (MCP)
Install the MCP server as a dotnet tool, then point your client at it:
dotnet pack src/OpenApiToOcelot.Mcp -c Release -o ./nupkg
dotnet tool install --global --add-source ./nupkg OpenApiToOcelot.Mcp
Example Claude Desktop / MCP client config:
{
"mcpServers": {
"openapi-to-ocelot": {
"command": "openapi-to-ocelot-mcp"
}
}
}
The server exposes four tools:
| Tool | Purpose |
|---|---|
generate_ocelot_config |
Convert a spec (inline / path / URL) and return ocelot.json + warnings |
preview_routes |
List the routes that would be generated, no JSON |
validate_openapi |
Report parse errors, warnings, operation count |
list_x_ocelot_extensions |
Catalog of supported x-ocelot-* extensions |
OpenAPI → Ocelot mapping
| OpenAPI | Ocelot |
|---|---|
paths./users/{id} |
UpstreamPathTemplate / DownstreamPathTemplate |
| HTTP methods under a path | grouped into UpstreamHttpMethod[] |
servers[0].url |
DownstreamScheme + DownstreamHostAndPorts + base path |
security / securitySchemes |
AuthenticationOptions.AuthenticationProviderKey + AllowedScopes |
operationId |
Route.Key |
x-ocelot-* extensions |
All remaining Ocelot options |
Bearer schemes map to "Bearer". OAuth2/OpenIdConnect schemes use the scheme name as AuthenticationProviderKey; the scopes listed in the requirement become AllowedScopes.
x-ocelot-* extensions
Place these on an operation or path-item to control a single route. The operation value wins over the path-item value.
paths:
/users:
get:
x-ocelot-rate-limit:
EnableRateLimiting: true
Period: 1s
PeriodTimespan: 1
Limit: 100
x-ocelot-qos:
ExceptionsAllowedBeforeBreaking: 3
DurationOfBreak: 5000
TimeoutValue: 2000
x-ocelot-file-cache: { TtlSeconds: 30, Region: users }
x-ocelot-security:
IPAllowedList: [10.0.0.0/8]
x-ocelot-add-headers:
X-User: "Claims[sub] > value"
Place these at the document root to populate GlobalConfiguration:
x-ocelot-base-url: https://gateway.example.com
x-ocelot-request-id-key: X-Request-Id
x-ocelot-service-discovery:
Type: Consul
Scheme: https
Host: consul.internal
Port: 8500
x-ocelot-load-balancer:
Type: LeastConnection
Full list: openapi-to-ocelot extensions (CLI) or list_x_ocelot_extensions (MCP tool).
Route grouping
By design, all HTTP methods sharing a path collapse into one Ocelot route — UpstreamHttpMethod becomes the list of methods. If two methods under the same path declare conflicting x-ocelot-* extensions, the converter takes the value from the first operation and emits a warning. Split the path or move the extension to the path-item level to silence it.
Build, test, run
dotnet build OpenAPISpecMCP.slnx
dotnet test OpenAPISpecMCP.slnx
dotnet run --project src/OpenApiToOcelot.Cli -- generate tests/OpenApiToOcelot.Tests/Fixtures/petstore.yaml
Snapshot tests use Verify. Promote any expected snapshot change by reviewing the .received.txt file and renaming it to .verified.txt.
Project layout
OpenAPISpecMCP/
├── global.json # SDK 10.0.300
├── Directory.Build.props # nullable, warnings-as-errors, SourceLink
├── Directory.Packages.props # central package management
├── OpenAPISpecMCP.slnx
├── src/
│ ├── OpenApiToOcelot.Core/ # converter library
│ ├── OpenApiToOcelot.Cli/ # dotnet tool — openapi-to-ocelot
│ └── OpenApiToOcelot.Mcp/ # MCP stdio server — openapi-to-ocelot-mcp
└── tests/
└── OpenApiToOcelot.Tests/ # xunit v3 + Verify snapshots
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
See RELEASE_NOTES.md