SDK

MCP servers

Connect Model Context Protocol servers to give the agent tools, resources, and prompts from anything that speaks MCP.

The mcp tool bridges the agent to any Model Context Protocol server — GitHub, Linear, a database, your internal services. Declared servers are started, their tools are discovered, and the agent can call them like built-ins.

Declaring servers

Servers can be launched as a subprocess (command) or reached over HTTP/SSE (url). Each entry is keyed by a short name the agent uses as a namespace.

agent = Harnext(
    provider="anthropic",
    mcp_servers={
        "github": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-github"],
            "env": {"GITHUB_TOKEN": os.environ["GITHUB_TOKEN"]},
        },
        "linear": {
            "url": "https://mcp.linear.app/sse",
            "mode": "proxy",
        },
    },
)

agent.run("Open a GitHub issue for the bug described in LIN-482")

Proxy vs. direct mode

  • direct (default) — the SDK connects to the server in-process and exposes its tools to the model.
  • proxy — the SDK fronts the server behind its own permission and logging layer, so MCP tool calls are gated by the same permission mode as built-in tools and recorded in the session.

Inspecting MCP tools

List what a connected server offers, or restrict which tools are exposed.

# What did the servers expose?
agent.mcp.servers()              # ["github", "linear"]
agent.mcp.tools("github")        # ["create_issue", "list_prs", ...]

# Only allow specific tools from a server
agent = Harnext(
    provider="anthropic",
    mcp_servers={
        "github": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-github"],
            "allow": ["create_issue", "add_comment"],
        },
    },
)
Treat MCP servers as untrusted input
An MCP server can return arbitrary content and tool definitions. Use proxy mode with an allow list for third-party servers, and keep credentials scoped to exactly what the server needs.