Skip to main content

Crate turbomcp_openapi

Crate turbomcp_openapi 

Source
Expand description

§TurboMCP OpenAPI Provider

Convert OpenAPI specifications to MCP tools and resources at runtime.

This crate enables automatic exposure of REST APIs as MCP components:

  • GET endpoints become MCP resources
  • POST/PUT/DELETE endpoints become MCP tools
  • Configurable route mapping patterns

§Example

use turbomcp_openapi::{OpenApiProvider, RouteMapping, McpType};

// Load from URL
let provider = OpenApiProvider::from_url("https://api.example.com/openapi.json")
    .await?
    .with_base_url("https://api.example.com")
    .with_route_mapping(RouteMapping::new()
        .map_method("GET", McpType::Resource)
        .map_method("POST", McpType::Tool)
        .map_pattern(r"/admin/.*", McpType::Tool));

// Use with TurboMCP server
let handler = provider.into_handler();

Modules§

prelude
Prelude for common imports.

Structs§

ExtractedOperation
An operation extracted from an OpenAPI spec.
ExtractedParameter
A parameter extracted from an OpenAPI operation.
OpenApiHandler
MCP handler that exposes OpenAPI operations as tools and resources.
OpenApiProvider
OpenAPI to MCP provider.
RouteMapping
Configuration for mapping OpenAPI operations to MCP components.
RouteRule
A single route mapping rule.

Enums§

McpType
MCP component type that an OpenAPI operation maps to.
OpenApiError
Errors that can occur during OpenAPI operations.

Functions§

parse_spec
Parse an OpenAPI specification from a string.

Type Aliases§

Result
Result type for OpenAPI operations.