feat(protocols): implement MCP JSON-RPC transport layer

Add complete MCP protocol implementation:
- mcp_types.rs: JSON-RPC types, initialize, tools, resources, prompts
- mcp_transport.rs: Stdio-based transport with split mutexes for stdin/stdout
- McpServerConfig builders for npx/node/python MCP servers
- Full McpClient trait implementation for tools/resources/prompts
- Add McpError variant to ZclawError

Transport supports:
- Starting MCP server processes via Command
- JSON-RPC 2.0 request/response over stdio
- Length-prefixed message framing
- Tool listing and invocation
- Resource listing and reading
- Prompt listing and retrieval

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-24 02:00:10 +08:00
parent d6df52b43f
commit 5a35243fd2
4 changed files with 709 additions and 0 deletions

View File

@@ -46,6 +46,12 @@ pub enum ZclawError {
#[error("Internal error: {0}")]
Internal(String),
#[error("Export error: {0}")]
ExportError(String),
#[error("MCP error: {0}")]
McpError(String),
}
/// Result type alias for ZCLAW operations