Skip to main content

mcp_kit.targets.oas

OpenAPI Specification (OAS) target implementation.

OasTarget

class OasTarget(Target)

Target implementation for OpenAPI Specification (OAS) endpoints.

This target creates MCP tools from OpenAPI specifications, allowing interaction with REST APIs through the MCP protocol.

__init__

def __init__(name: str, spec_url: str) -> None

Initialize the OAS target.

Arguments:

  • name: Name of the target
  • spec_url: URL of the OpenAPI specification

name

@property
def name() -> str

Get the target name.

Returns:

The target name

from_config

@classmethod
def from_config(cls, config: DictConfig) -> Self

Create OasTarget from configuration.

Arguments:

  • config: Target configuration from OmegaConf

Returns:

OasTarget instance

initialize

async def initialize() -> None

Initialize the target by creating MCP server from OpenAPI spec.

Downloads and parses the OpenAPI specification to create the underlying FastMCP server with tools for each API endpoint.

list_tools

async def list_tools() -> list[Tool]

List all tools generated from the OpenAPI specification.

Raises:

  • ValueError: If the target is not initialized

Returns:

List of tools corresponding to API endpoints

call_tool

async def call_tool(name: str,
arguments: dict[str, Any] | None = None) -> list[Content]

Call an API endpoint through the corresponding MCP tool.

Arguments:

  • name: Name of the tool/endpoint to call
  • arguments: Arguments to pass to the API endpoint

Raises:

  • ValueError: If the target is not initialized

Returns:

List of content responses from the API call

close

async def close() -> None

Clean up the target by releasing the FastMCP server.

run_async

async def run_async(oas_name: str, spec_url: str, port: int) -> None

Run the OAS target as a standalone HTTP server.

Arguments:

  • oas_name: Name for the OAS instance
  • spec_url: URL of the OpenAPI specification
  • port: Port to run the server on

Raises:

  • ValueError: If the target fails to initialize

run_sync

@click.command()
@click.option(
"--oas-name",
default="oas",
help="Name of the OAS instance (default: oas)",
)
@click.option("--spec-url", required=True, help="OpenAPI spec URL")
@click.option(
"--port",
default=9000,
show_default=True,
help="Port to run the server on",
)
def run_sync(oas_name: str, spec_url: str, port: int) -> None

Synchronous wrapper for running the OAS target server.

Arguments:

  • oas_name: Name for the OAS instance
  • spec_url: URL of the OpenAPI specification
  • port: Port to run the server on