Skip to content

feat(tools): add Model Context Protocol (MCP) client adapter for external tools #12

Description

@Kaap10

Problem Statement

Terminal Agent is currently restricted to its 12 built-in tools. Developers cannot connect external tool ecosystems (such as database query runners, browser inspectors, GitHub API integrations, or custom debuggers) into the agent loop.

Proposed Architecture & Solution

  1. MCP Client Adapter (src/terminal_agent/tools/mcp.py):
    • Implement an MCP client communicating via stdio JSON-RPC with configured MCP servers.
    • Discover available tools using the MCP tools/list protocol.
    • Wrap MCP tool definitions as BaseTool instances compatible with ToolRegistry.
  2. Configuration Support (src/terminal_agent/config/schema.py):
    • Add mcp_servers configuration to TerminalAgentConfig:
      mcp_servers:
        postgres:
          command: "npx"
          args: ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
        github:
          command: "docker"
          args: ["run", "-i", "--rm", "mcp/github"]
          env:
            GITHUB_PERSONAL_ACCESS_TOKEN: "${GITHUB_TOKEN}"
  3. Registry Integration (src/terminal_agent/tools/registry.py):
    • Initialize and register active MCP server tools during ToolRegistry setup.
    • Cleanly handle MCP server shutdown on session completion.

Files to Modify / Create

  • src/terminal_agent/tools/mcp.py (New)
  • src/terminal_agent/tools/registry.py
  • src/terminal_agent/config/schema.py
  • tests/unit/test_mcp.py (New)

Acceptance Criteria

  • MCP stdio server tools are discovered and converted to LLM-compatible tool schemas.
  • Tool execution dispatches JSON-RPC tools/call requests and returns structured ToolResult.
  • Graceful fallback and error handling if an MCP server fails to start or crashes.
  • Mock MCP server unit test verifying schema generation and tool invocation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions