Implements the Model Context Protocol (MCP) for bidirectional tool discovery and invocation. Acts as both MCP client (consuming external MCP servers) and MCP server (exposing TeaAgent tools to external clients).
- Session lifecycle —
initialize()must be called first; returns server capabilities and storessession_id. - Tool discovery —
list_tools()returns the server's available tools. - Tool invocation —
call_tool(name, arguments)invokes a server tool;isError: trueresults raiseMCPClientError. - Session close —
close()sends DELETE to terminate the session; accepts 204 or 404 (already closed). - Transport — stdlib
http.clientonly, no third-party HTTP libraries. Supportshttpandhttps.
- JSON-RPC 2.0 — all messages follow JSON-RPC protocol over Streamable HTTP.
- Session management — each client gets a
Mcp-Session-Idheader; stateless requests include session in path or header. - Tool registration — TeaAgent's
ToolRegistrytools are exposed as MCP tools; input_schema is forwarded as-is. - OAuth —
mcp_http/_oauth.pyhandles OAuth 2.1 authorization for authenticated MCP servers.
- Trust levels — each MCP server has a trust level:
TRUSTED,VERIFIED,UNTRUSTED. - Tool filtering — untrusted servers cannot register tools that match sensitive name patterns.
- Capability scope — trusted servers get full tool access; others are scoped.
- Single-shot — no session state; each request is self-contained.
- Use case — CI/batch environments where session management overhead is not needed.
MCPHTTPClient.initialize()must be called beforelist_tools()orcall_tool().session_idis set afterinitialize()and cleared afterclose().call_tool()withisError: truealways raisesMCPClientError, never returns.- MCP server tool names must match the TeaAgent
ToolDefinition.name.