Skip to content

MCP Driver part 1: stdio transport + auto-discovery #53

@dgenio

Description

@dgenio

Parent: #41 | Split: stdio transport + auto-discovery

Problem

This is part 1 of #41 (MCP Driver). It covers the stdio transport — connecting to local MCP servers via subprocess — and the auto-discovery mechanism that converts MCP tools/list results into kernel Capability objects.

Proposed Change

1. MCPDriver core + stdio transport

class MCPDriver:
    """Driver that connects to an MCP server and executes tool calls."""
    
    async def execute(self, operation: str, params: dict, constraints: dict) -> Any:
        """Map operation → tools/call, apply constraints, return result."""
  • stdio transport: Connect to local MCP servers via mcp.client.stdio.stdio_client.
  • Factory method: MCPDriver.from_stdio(command, args).
  • Async context manager for connection lifecycle.

2. Auto-discovery

  • MCPDriver.discover() -> list[Capability]: Call tools/list, convert each MCP tool to a Capability.
  • capability_id = tool name, description from MCP tool, safety_class = READ (overridable).

3. Response handling

  • Convert MCP CallToolResult content blocks to dicts for the firewall.
  • Handle isError by raising DriverError.

Acceptance Criteria

  • MCPDriver.from_stdio() connects to a local MCP server process
  • discover() converts MCP tools to Capability objects with correct metadata
  • execute() calls MCP tools and returns results through the firewall pipeline
  • Error responses raise DriverError with descriptive message
  • Integration test with mock MCP server (FastMCP) exercises full pipeline
  • mcp>=1.0 added as optional dependency
  • Graceful ImportError when mcp package not installed

Affected Files

  • src/agent_kernel/drivers/mcp.py (new)
  • src/agent_kernel/drivers/__init__.py (export)
  • tests/test_drivers.py (integration tests)
  • pyproject.toml (optional dep)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions