Skip to main content

mcp.tools

Tools integration for agent-runtimes using MCP (Model Context Protocol).

This module provides MCP tools integration that can be used by both Jupyter and FastAPI servers.

generate_name_from_id

def generate_name_from_id(tool_id: str) -> str

Generate a display name from a tool ID.

Replaces underscores with spaces and capitalizes the first letter.

Arguments:

  • tool_id - Tool identifier (e.g., "notebook_run-all-cells")

Returns:

Formatted name (e.g., "Notebook run-all-cells")

tools_to_builtin_list

def tools_to_builtin_list(tools: list[dict[str, Any]]) -> list[BuiltinTool]

Convert tool dictionaries to BuiltinTool objects.

Arguments:

  • tools - List of tool dictionaries with 'name' and optional 'description'

Returns:

List of BuiltinTool objects

create_mcp_server

def create_mcp_server(base_url: str,
token: str | None = None) -> MCPServerStreamableHTTP

Create an MCP server connection.

The MCP server runs on the same server and exposes tools via the MCP protocol over HTTP.

Arguments:

Returns:

MCPServerStreamableHTTP instance connected to the MCP server

get_tools_from_mcp

async def get_tools_from_mcp(base_url: str,
token: str | None = None) -> list[dict[str, Any]]

Get available tools from an MCP server.

Connects to the MCP server using pydantic-ai's MCP client and queries tools through the standard MCP protocol.

Arguments:

  • base_url - Server base URL
  • token - Authentication token

Returns:

List of tool dictionaries with name, description, and inputSchema

get_available_tools

async def get_available_tools(
base_url: str,
token: str | None = None,
enabled_only: bool = True) -> list[dict[str, Any]]

Get available tools (backward compatible wrapper).

Arguments:

  • base_url - Server base URL
  • token - Authentication token
  • enabled_only - Ignored (kept for backward compatibility)

Returns:

List of tool dictionaries

extract_tool_names

def extract_tool_names(tools: list[dict[str, Any]]) -> list[str]

Extract tool names from tools list.

Arguments:

  • tools - List of tool dictionaries

Returns:

List of tool names/IDs