MCP & Client

MCP Client Protocol Negotiation, Transport Layer & Credential Sanitization

Decrypting tools/mcp_tool.py stdio/SSE handshake details & API error desensitization
Tool dynamic negotiation
📊 Fig 10-2-1: AIAgent, MCP Client & external MCP Servers tool discovery and dynamic negotiation UML sequence diagram

🔌 1. stdio / SSE Transport Protocol Handshake

In tools/mcp_tool.py, the system has built-in support for the Model Context Protocol (MCP) standard transport layer. It spawns a child process and binds stdin/stdout to establish transport, or uses a persistent connection (SSE) to listen for real-time tool broadcasts.

Transport protocol layers
📊 Fig 10-2-2: MCP Client & MCP Servers stdio, SSE and StreamableHTTP transport detail diagram

🔒 2. Security & Credential Sanitization (_sanitize_error)

Tool error messages are directly returned as context to the LLM. In mcp_tool.py, the _sanitize_error() method uses strict regex sanitization to filter out ghp_, sk-, Bearer tokens, and API_KEY keywords, preventing credential leakage through tool error messages.