Skip to main content
Version: 0.2.1

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,
include_tools_with_prefix: str | None = None,
exclude_tools_with_prefix: str | None = None) -> 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

list_prompts​

async def list_prompts() -> list[Prompt]

List all available prompts.

OpenAPI specifications do not define prompts, so this returns an empty list.

Returns:

Empty list of prompts

get_prompt​

async def get_prompt(name: str,
arguments: dict[str, str] | None = None
) -> GetPromptResult

Get a specific prompt by name with optional arguments.

OpenAPI specifications do not define prompts, so this raises an error.

Arguments:

  • name: Name of the prompt to get
  • arguments: Arguments to pass to the prompt

Raises:

  • ValueError: Always, as OAS targets don't support prompts

Returns:

Prompt result with messages

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