Streaming Python MCP Client SDK with Elicitation and Codegen
生产级流式 Python MCP 客户端 SDK,支持 Streamable HTTP/stdio、会话恢复、进度流、Elicitation 交互、Sampling 回调与 JSON Schema 强类型代码生成。
You are an SDK engineer. Build a production Python MCP client SDK (Python 3.12+) supporting Streamable HTTP, stdio, resumable sessions, streaming output, and elicitation. Consumers are agent frameworks inside [INSERT ORGANIZATION] that need typed, async tool access to [INSERT NUMBER] MCP servers. Output modules sequentially and pause for my review. Module 1 API design: async client surface, typed tool wrappers generated from JSON schema, resource readers, and prompt rendering; show usage examples first. Module 2 Transports: stdio subprocess and Streamable HTTP with SSE, automatic reconnect with backoff, session-ID resume, and strict spec-version checks. Module 3 Streaming: async iterators for progress notifications and streamed tool output, backpressure, and partial-result handling. Module 4 Elicitation: a pluggable handler protocol for structured user-input requests, timeouts, defaults, and cancellation semantics. Module 5 Server-initiated features: client callbacks for sampling and logging with policy hooks and budget caps. Module 6 Security: OAuth 2.1 device/browser flows, token-storage abstraction, server allowlist, optional TLS pinning, and audit hooks. Module 7 Resilience: per-call deadlines, retries keyed to idempotentHint, hedging, jitter, and idempotency-key management. Module 8 Observability: OpenTelemetry context propagation, structured logging with session/tool fields, and no-op telemetry by default. Module 9 Codegen: a CLI generating typed tools from a live server or cached schema, with regeneration checks enforced in CI. Module 10 Testing: pytest suite against a reference in-process server, transport fault injection, property tests for schema models, and mypy strict. Module 11 Packaging: uv-managed project, py.typed marker, cryptographically signed releases, changelog, and migration guide. Module 12 Docs: quickstart, async concurrency patterns, threading model, and an end-to-end example agent using [INSERT MODEL PROVIDER]. Specify compatibility guarantees, deprecation policy, and minimum supported MCP spec versions. Begin with five design questions about Python-version support, sync-wrapper needs, and enterprise-proxy constraints. ================
自动翻译
自动翻译中…