MCP Tool Ecosystem
Video (best)
- None identified
Blog / Written explainer (best)
- Anthropic — “Model Context Protocol (MCP)”
- Link: https://modelcontextprotocol.io/
- Why: Canonical, up-to-date overview of MCP concepts (clients/servers, primitives, transports) with documentation-style explanations.
- Level: beginner/intermediate
Deep dive
- Anthropic (GitHub) — “Model Context Protocol” (specs, SDKs, examples)
- Link: https://github.com/modelcontextprotocol
- Why: Primary source for deeper details: protocol spec, reference implementations, and practical examples that clarify tool/resource/prompt primitives and composability patterns.
- Level: intermediate/advanced
Original paper
- None identified
Code walkthrough
- Anthropic — “Build an MCP Server”
- Link: https://modelcontextprotocol.io/quickstart
- Why: Official quickstart with runnable examples for building MCP servers, wiring clients, and understanding transports.
- Level: intermediate
Coverage notes
- Strong: Model Context Protocol basics; MCP clients vs servers; tool/resource/prompt primitives; practical building guidance via official docs/repos.
- Weak: Independent third-party deep dives; comparative evaluations of tool registries and discovery patterns across ecosystems.
- Gap: A widely-cited, neutral “tool discovery + registries + client integration” explainer with concrete best practices and security considerations across transports.
Additional Resources for Tutor Depth
16 sources — papers, official docs, working code, benchmarks, and deep explainers that give the AI tutor precision on this topic.
📄 MCP Production Deployment Patterns (CABP, ATBA, SERF)
Paper · source
Production procedures: observability/instrumentation, latency SLOs, threat model, production readiness checklist for MCP deployments
Key content
- MCP production gaps (Abstract/Intro): missing protocol primitives: identity propagation, adaptive tool budgeting, structured error semantics → proposed mechanisms CABP, ATBA, SERF.
- CABP broker pipeline (Sec. 5.3, 12.1): six stages per JSON-RPC request:
- JWT extraction from
Authorizationheader - JWT validation (signature via JWKS, expiry, issuer)
- Tool-level ACL resolution/enforcement
- Context injection (inject
tenant_id,user_id, scopes into request context) - Response sanitization (strip cross-tenant records)
- Audit emission (log identity, tool, sanitized inputs, output summary, latency, status)
Ops default: validate JWT every request; if expired mid-chain return -32600; never cache tokens.
Hypothesis H2: CABP adds <15ms median overhead.
- JWT extraction from
- Timeouts & async (Sec. 6): sequential chain example typical latencies: 200ms + 150ms + 300ms + 400ms + 500ms planner = 1,550ms. Failure modes: per-tool timeout (30s), chain/session timeout (100s default), planner budget exhaustion, orphaned responses.
MCP Tasks pattern:tools/callwithtask_augment:true→ returntaskId(~50ms) → polltasks/getwith exponential backoff (1s start, 30s cap) → terminal status. Task TTL: 15 min. Rate-limit mispolling: 429 + Retry-After if >1 req/s. - Latency SLOs (Sec. 6.3, 8.4): p99 targets: 500ms reads, 2s moderate queries, 5s writes; anything >10s → async Tasks. Alert on p99 per-tool exceeding planner budget.
- SERF structured tool errors (Sec. 7, 12.3): tool errors via
CallToolResultwithisError:trueshould includeretryable+suggested_action(s); taxonomy:INVALID_INPUT,RESOURCE_NOT_FOUND,RESOURCE_EXHAUSTED,PERMISSION_DENIED,UPSTREAM_FAILURE,INTERNAL_ERRORwith deterministic recovery mapping. - Write safety (Sec. 7.4): writes require
idempotency_key; store key→response in Redis/DynamoDB with 24h TTL. Suggested caching: 30s TTL usage data; 5 min project lists. - Observability checklist (Sec. 8): instrument per-request fields (request_id, tool_name, user_id, tenant_id, latency_ms, status, error_code, output_size_bytes), aggregated p50/p95/p99 per tool,
/health+/ready, security metrics (auth failures, token validation failures, cross-tenant attempts target 0). Use OpenTelemetry trace propagation (parent trace per user request; span per tool call). - Threat model (Sec. 9): T1 prompt injection via tool responses → broker sanitization + output schema enforcement; T2 data exfiltration → input minimization + broker auditing + egress allowlist; T3 privilege escalation via tool chaining → broker ACLs + explicit confirmation for side-effect tools + chain policy; T4 DoS via slow/large responses → broker timeouts + response size limits + circuit breakers.
- Production readiness checklist (Sec. 11):
Contract: descriptive tool names/descriptions; typed JSON Schema; side effects + idempotency documented.
Resilience: Tasks for long ops; idempotency keys; structured errors; circuit breakers.
Operations: health/readiness; per-tool metrics; broker JWT+ACL; audit log.
📄 MCP Security & Safety Threat Taxonomy + Defenses
Paper · source
Threat taxonomy + security/trust model for MCP ecosystems (prompt/tool/context attacks, governance layers, mitigations)
Key content
- MCP architecture/security boundary (Sec. II): Host mediates all LLM interactions; LLM never connects directly to data sources/tools. Protocol uses JSON-RPC 2.0 over Stdio (local isolation) or SSE (remote). Starts with capability negotiation handshake (declare supported features like resources/prompts/logging).
- Core primitives (Sec. II-C):
- Resources: read-only context streams identified by URIs (e.g.,
file:///logs/error.txt), can support subscriptions. - Prompts: server-defined templates bundling resources + instructions (“best practice workflows”).
- Tools: executable actions exposed by servers; host is policy enforcement point.
- Resources: read-only context streams identified by URIs (e.g.,
- Security vs Safety convergence (Sec. I-B, III-B): security breaches (e.g., indirect prompt injection) can trigger safety failures (model “honestly” believes it’s authorized), and safety failures (hallucinated parameters) can cause security breaches (exfiltration).
- Security vulnerability taxonomy (Table III, Sec. IV-A):
Context Poisoning; Prompt Injection; Unauthorized Context Injection; Data Leakage & Privacy; Cross-Session Contamination; Supply-Chain & Model-Switch; Protocol Abuse & Name Collisions; DoS & Resource Exhaustion. Includes phases (Install/Update/Exec) and impacts (e.g., unauthorized command execution, integrity breach, cost escalation). - Concrete empirical result (Sec. VII-A): 43% of MCP server implementations tested (Equixly) executed unsafe shell calls, enabling RCE risk.
- Mitigation stack (Sec. VI):
- ETDI: cryptographically signed tool manifests, immutable version identifiers, registry-based approval; verify signatures at load + invocation; re-authorization on functional change (anti “rug-pull”).
- Capability-bound execution: OAuth-enhanced tool definitions, least privilege, short-lived creds, mTLS, continuous verification (Zero Trust).
- Context validation/sanitization: strict delimiters separating system/user/tool content; deterministic filtering of tool outputs; provenance tracking (e.g., DDG/MindGuard).
- Isolation + integrity: sandboxing (e.g., gVisor syscall interception); schema validation + signatures + nonces/timestamps to prevent replay.
📄 Retriever-Aware Training (RAT) for API/Tool Calling (Gorilla)
Paper · source
RAT procedure for tool/API call generation conditioned on retrieved API docs + evaluation vs strong baselines
Key content
- Dataset (APIBench) construction (Sec. 3.1):
- 1,645 APIs total: TorchHub 95 (exhaustive), TensorFlow Hub v2 626 (filtered from 801), HuggingFace 925 (top-20 per domain).
- Each API converted to JSON fields:
{domain, framework, functionality, api_name, api_call, api_arguments, environment_requirements, example_code, performance, description}. - Self-instruct: GPT-4 generates 10 instructions per API → 16,450 {instruction, API} pairs; only 18 seed examples hand-made (6 per hub).
- Retriever-Aware Training (RAT) (Sec. 3.2):
- Training prompt appends retrieved doc:
<user_prompt> Use this API documentation for reference: <retrieved_API_doc_JSON> - Rationale: retrieved docs may be wrong (imperfect recall); RAT teaches model to use relevant docs and ignore irrelevant retrieval (“judge the retriever”), reducing hallucinations and improving robustness to test-time doc/API changes.
- Inference modes: zero-shot (no retriever) vs retrieval (BM25 or GPT-Index top-1 doc appended; no extra prompt tuning).
- Training prompt appends retrieved doc:
- Evaluation metrics (Sec. 3.3):
- AST subtree matching for functional correctness of single API call.
- Hallucination definition: generated API call not a subtree of any API in database; accuracy + error + hallucination = 1.
- Human check: AST accuracy 0.78 = human 0.78; code executable 0.72 (100-sample).
- Key empirical results (Table 1, 2):
- TorchHub, GPT-Index retriever: Gorilla 61.82% acc, 0% halluc vs GPT-4 59.13% acc, 1.07% halluc.
- Zero-shot TorchHub: Gorilla 59.13% acc, 6.98% halluc vs GPT-4 38.70% acc, 36.55% halluc.
- Oracle retriever + Gorilla: TorchHub 67.20% acc (0% halluc); HuggingFace 91.26% acc; TensorHub 94.16% acc.
- Retrieval gap (Table 2, Gorilla trained w/ oracle retriever): eval with GPT-Index degrades 29.20% acc, BM25 degrades 52.27% acc vs oracle.
- Defaults / hyperparameters (App. A.2, Table 6):
- Train 5 epochs, lr 2e-5 (cosine decay), batch 64, warmup 0.03, weight decay 0, max seq 2048, on 8×A100 40GB.
- Splits: HuggingFace 90/10, TorchHub & TensorHub 80/20.
📄 StableToolBench — stabilizing ToolBench evaluation & APIs
Paper · source
ToolBench instability causes + StableToolBench virtual API server + stable metrics (SoPR/SoWR) and protocols.
Key content
- ToolBench instability evidence (Section 2):
- Reproduced Pass Rates on ToolBench I1-Instruction drop vs reported (Table 9):
- GPT-3.5-0613+CoT: 41.5 → 35.2 (−32.5%)
- ToolLLaMA v2+CoT: 25.0 → 15.0 (−40%)
- ToolLLaMA v2+DFS: 57.0 → 34.0 (−40.4%)
- API status drift: only 44.4% success, 49.2% not available, 6.4% not authorised (Table 10). Not-available breakdown: parsing error 52.6%, not connectable 30.0%, parameter change 7.3%, not found 7.2% (Table 11).
- Reproduced Pass Rates on ToolBench I1-Instruction drop vs reported (Table 9):
- Virtual API server (Section 3.1):
- Cache key: (category, tool, API name, arguments).
- Calling rule: cache hit → return; else try real API; if real API unavailable → LLM API simulator; then save response back to cache.
- Cache sizes (Table 2): before filtration 352,630, after 164,980.
- Simulator uses gpt-4-turbo, conditioned on API docs + up to 5 few-shot cached real calls.
- Stable evaluation system (Section 3.2):
- Solvable-task filtering: majority vote of gpt-4-turbo, gemini-pro, claude-2; solvable if ≥2 vote solvable. Total tasks 1,100, solvable 765 (Table 3).
- SoPR (Solvable Pass Rate): evaluate only solvable tasks with gpt-4-turbo; answer label → score: Solved=1, Unsolved=0.5, Unsure=0.
- SoWR: if one solved & other unsolved → solved wins; otherwise gpt-4-turbo decides.
- Evaluator reliability (Table 8): GPT-4 Turbo accuracy: solvability 80%, answer-solving 74%, comparison 78% vs GPT-3.5: 65% / 68% / 56%.
- Stability under tool failures: with virtual server, SoPR changes remain within variance even when 50% tools forced down (Figure 7/Table 12).
📊 Berkeley Function Calling Leaderboard (BFCL) — benchmark scope & evaluation design
Benchmark · source
Standardized evaluation of LLM tool/function-calling (incl. serial/parallel calls, abstention, stateful multi-step), using AST-based validity checking; points to the live leaderboard.
Key content
- Definition (task): Function calling / tool use = an LLM invoking external functions/APIs/user-defined tools in response to user queries (agentic capability).
- Benchmark purpose (design rationale): Created because there previously was no standard benchmark for function calling due to:
- difficulty of evaluating whether a function call is valid, and
- difficulty acquiring diverse, real-world functions.
- Evaluation coverage (procedures):
- Evaluates serial and parallel function calls.
- Covers functions across various programming languages.
- Uses a novel Abstract Syntax Tree (AST) evaluation method to judge calls; designed to scale to thousands of functions.
- Benchmark construction uses a mix of expert-curated and user-contributed functions + associated prompts.
- Includes evaluation of abstention and reasoning in a stateful multi-step agentic setting (not just single-turn).
- Empirical takeaway (qualitative result): Across many models, state-of-the-art LLMs excel at single-turn calls, but memory, dynamic decision-making, and long-horizon reasoning remain open challenges.
- Where metrics live: The paper states BFCL is accessible via the public leaderboard: gorilla.cs.berkeley.edu/leaderboard.html (periodically updated).
📖 Claude Code ↔ MCP integration & deployment patterns
Reference Doc · source
Real integration topology + configuration/ops constraints for connecting Claude Code (MCP client) to MCP servers (HTTP/SSE/stdio), incl. auth, scopes, governance, and output/tool-search limits.
Key content
- MCP server transport options (recommended order):
- Remote HTTP (recommended for remote/cloud services; most widely supported)
- Remote SSE
- Local stdio (runs local process; best for direct system access/custom scripts)
- CLI ordering rule (critical): options
--transport,--env,--scope,--headermust come before the server name; use--to separate server name from command/args passed to server.- Example:
claude mcp add --transport stdio myserver -- npx server - Example:
claude mcp add --transport stdio --env KEY=value myserver -- python server.py --port 8080
- Example:
- Dynamic capability refresh: supports
list_changednotifications → tools/prompts/resources refresh without reconnect. - Channels (push into session): server declares
claude/channel; client opts in with--channelsat startup. - Scopes & precedence: local (default, private; stored in
~/.claude.jsonunder project path) vs project (team-shared.mcp.jsonat repo root) vs user (~/.claude.json, cross-project). Precedence: local > project > user. Local overrides Claude.ai connector entries. .mcp.jsonenv expansion:${VAR}and${VAR:-default}supported incommand,args,env,url,headers.- OAuth specifics: default callback uses random port; fix with
--callback-portfor pre-registered redirecthttp://localhost:PORT/callback. If no Dynamic Client Registration, use--client-id+--client-secret(masked prompt). Override discovery viaoauth.authServerMetadataUrl(requires Claude Code v2.1.64+). - Custom auth headers:
headersHelperruns shell command (10s timeout) returning JSON headers; dynamic overrides static. Env vars:CLAUDE_CODE_MCP_SERVER_NAME,CLAUDE_CODE_MCP_SERVER_URL. Runs only after workspace trust (project/local scope). - Output limits: warn at 10,000 tokens; default max 25,000 tokens; configurable via
MAX_MCP_OUTPUT_TOKENS. Per-tool override via_meta["anthropic/maxResultSizeChars"]up to 500,000 chars. - Tool Search: enabled by default (defer schemas; load on demand). If
ANTHROPIC_BASE_URLis non-first-party, tool search disabled by default unlessENABLE_TOOL_SEARCHset. Values: unset /true/auto/auto:<N>(0–100%) /false. Requires models supportingtool_reference(Sonnet 4+, Opus 4+; Haiku unsupported). - Org governance: exclusive
managed-mcp.json(system paths: macOS/Library/Application Support/ClaudeCode/managed-mcp.json; Linux/WSL/etc/claude-code/managed-mcp.json; WindowsC:\Program Files\ClaudeCode\managed-mcp.json). Or allow/deny lists (allowedMcpServers,deniedMcpServers) matching byserverName, exactserverCommandarray, or wildcardserverUrlpatterns; denylist overrides allowlist.
📖 LangChain MCP client behavior & adapter patterns
Reference Doc · source
Concrete client integration behavior/defaults (stateless MultiServerMCPClient; per-invocation session lifecycle) + adapter-based tool/resource/prompt consumption.
Key content
- Definition: MCP is an open protocol standardizing how apps provide tools + context to LLMs; LangChain uses langchain-mcp-adapters (built on the official MCP Python SDK) to consume MCP servers.
- Default client lifecycle (stateless):
MultiServerMCPClientis stateless by default: each tool invocation creates a freshClientSession, executes the tool, then cleans up (per-invocation session lifecycle). - Stateful sessions (procedure): If you need persistent context across calls (stateful server), explicitly manage lifecycle by creating a persistent
ClientSessionviaclient.session()(controls MCP session lifecycle per MCP spec). - Transports (comparison + rationale):
- HTTP / streamable-http: Uses HTTP requests; supports custom headers via connection config
headers(also supported for SSE, but SSE is deprecated by MCP spec). - stdio: Client launches server as a subprocess and communicates over stdin/stdout; inherently stateful because subprocess persists for lifetime of the connection. However, with
MultiServerMCPClientwithout explicit session management, each tool call still creates a new session.
- HTTP / streamable-http: Uses HTTP requests; supports custom headers via connection config
- Auth mechanism: Provide custom auth by implementing
httpx.Auth(supported via MCP SDK). - Adapter conversions (how LangChain consumes MCP primitives):
- Tools: MCP tools → LangChain tools; load via
client.get_tools(). - Structured tool output: If tool returns
structuredContent, adapter wraps it asMCPToolArtifactaccessible viaToolMessage.artifact; interceptors can transform/append it. - Multimodal tool output: Multi-part content (text/images) → LangChain standard content blocks; access via
ToolMessage.content_blocks. - Resources: MCP resources → LangChain
Blob; load viaclient.get_resources()(orload_mcp_resourceswith a session). - Prompts: MCP prompts → LangChain messages; load via
client.get_prompt()(orload_mcp_promptwith a session).
- Tools: MCP tools → LangChain tools; load via
- Interceptors (design rationale): MCP servers are separate processes and can’t access LangGraph runtime (store/context/state); interceptors provide middleware-like control (modify requests, retries, dynamic headers, short-circuit) and can return
Commandto update state/control flow (e.g.,goto="__end__").
📖 Responses API Function/Tool Calling (fields + flow)
Reference Doc · source
Exact Responses API tool/function-calling request/response fields, tool_choice behavior, tool call objects/arguments, and returning tool results.
Key content
- Tool-calling workflow (5 steps): (1)
responses.create(..., tools=..., input=...)→ (2) model returns tool call(s) inresponse.output→ (3) app executes tool(s) using provided args → (4) append tool results asfunction_call_outputitems → (5) callresponses.createagain with updatedinputto get final answer (or more calls). - Tool definition (function tool schema):
tools: [{ "type":"function", "name", "description", "parameters": JSONSchema, "strict": bool }] - Function call item (in
response.output):
{ "type":"function_call", "id":"fc_…", "call_id":"call_…", "name":"get_weather", "arguments":"{...JSON string...}" }
argumentsis JSON-encoded string; parse withjson.loads(...). - Returning tool results to model: append to next request
input:
{ "type":"function_call_output", "call_id": <matching call_id>, "output": <string | array of image/file objects> } - Multiple calls: assume 0/1/many tool calls per response; iterate
response.outputand handle eachfunction_call. - Reasoning models requirement: for GPT-5 / o4-mini, pass back any reasoning items from model responses along with tool outputs in the next
input. - tool_choice options (defaults/controls):
- Default:
"auto"(model may call 0/1/many tools) "required"(must call ≥1 tool)- Force one tool:
{"type":"function","name":"get_weather"} - Restrict without changing
tools:{"type":"allowed_tools","mode":"auto","tools":[{"type":"function","name":"get_weather"}, ...]} "none"imitates no tools.
- Default:
- Parallel calls: set
parallel_tool_calls: falseto ensure exactly 0 or 1 tool call per turn. Not available with built-in tools. - Strict mode (recommended):
strict:trueenforces schema via structured outputs. Requirements: every object hasadditionalProperties:false; allpropertiesfields listed inrequired; optional via union withnull(e.g.,"type":["string","null"]). In Responses API, schemas are normalized into strict by default unlessstrict:false.
📖 Streaming Responses API — event sequence & assembly
Reference Doc · source
Streaming event sequence + ordering/termination semantics (incl. tool/function-call argument deltas)
Key content
- Enable streaming (Responses API): set
stream: true/stream=Trueinclient.responses.create(...). Iterate events (for await ... of streamin JS;for event in streamin Python). - Core lifecycle events (text):
response.created→ start boundary (containsresponse.id)response.output_text.delta→ incremental token indeltaresponse.completed→ end boundary (contains fullresponse)error/response.error→ failure handling
- Event typing: each streamed object has
type(schema-defined). Useful types include:
response.output_item.added/done,response.content_part.added/done,response.output_text.delta,response.text.done, plus tool-related:response.function_call_arguments.deltaandresponse.function_call_arguments.done. - Text assembly procedure (message-per-token):
- On
response.output_item.added, noteoutput_indexanditem.idwhenitem.type === "message". - On
response.content_part.added, notecontent_indexfor the message item. - Append each
response.output_text.delta.deltaonly when(event.item_id, output_index, content_index)match the target message content part. - Treat
response.content_part.done/response.output_item.doneas “part/item fully generated”;response.completedas final completion boundary.
- On
- Tool/function-call argument assembly (streaming):
- Accumulate
response.function_call_arguments.deltachunks in order for a given call (correlate by the event’s identifiers); finalize whenresponse.function_call_arguments.donearrives, then parse the completed arguments string (e.g., JSON) before executing the tool.
- Accumulate
- Design rationale: Responses API streaming uses semantic, type-safe events (preferred over legacy chunked streaming) to let apps listen only to relevant events and reliably reconstruct outputs.
📖 Streaming tool args — response.function_call_arguments
Reference Doc · source
Exact streaming field name(s) and payload shape used to reconstruct tool/function call arguments
Key content
- Endpoint:
POST /v1/responsescreates a model response; supports streaming via Server-Sent Events (SSE) whenstream: true. - Streaming control (request):
stream: boolean— iftrue, response data is streamed as generated (SSE).stream_options: { include_obfuscation }— only set whenstream: true.
- Tool/function calling configuration (request):
tools: [...]— list of tools the model may call (built-in tools, MCP tools, or function calls/custom tools with typed args).tool_choice— controls how the model selects tools (e.g.,"auto").parallel_tool_calls: boolean— whether tool calls may run in parallel.max_tool_calls: number— maximum total built-in tool calls processed in a response (across all built-in tools).
- Include extra tool-related outputs (request
include: [...]):web_search_call.action.sourcescode_interpreter_call.outputscomputer_call_output.output.image_urlfile_search_call.resultsmessage.input_image.image_urlmessage.output_text.logprobsreasoning.encrypted_content
- Non-streamed response shape example (for orientation):
- Top-level
Responseincludesid,object:"response",status,output:[...],tools:[],tool_choice,parallel_tool_calls,usage, etc. - Assistant text appears under
output[].type:"message" → content[].type:"output_text" → text.
- Top-level
📖 Structured Outputs / JSON mode (doc index only)
Reference Doc · source
JSON/Structured Outputs constraints & guarantees (JSON mode vs schema-based structured outputs; refusal signaling; schema definition/validation helpers)
Key content
- This fetch returned a 404 “Page not found” for the target URL; no JSON-mode/structured-output constraints, guarantees, parameters, or examples are present in the retrieved text.
- The retrieved content is navigation-only for the OpenAI docs site and includes links (no technical details) to:
- Structured output guide:
https://platform.openai.com/api/docs/guides/structured-outputs - Function calling guide:
https://platform.openai.com/api/docs/guides/function-calling - Using tools guide:
https://platform.openai.com/api/docs/guides/tools - Responses API migration guide:
https://platform.openai.com/api/docs/guides/migrate-to-responses
- Structured output guide:
- No extractable items from this source for:
- Formulas/equations: none
- Empirical results / numbers: none (beyond HTTP 404)
- Procedures/steps: none
- Defaults/parameters: none
- Design rationale: none
📋 # Source: https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle
Source ·
📋 # Source: https://modelcontextprotocol.io/specification/2025-06-18/server/prompts
Source ·
📋 # Source: https://modelcontextprotocol.io/specification/2025-06-18/server/tools
Source ·
📋 # Source: https://modelcontextprotocol.io/specification/2025-11-25
Source ·
📋 MCP stdio server end-to-end wiring (TypeScript SDK)
Code · source
End-to-end stdio server setup pattern using MCP SDK (newline-delimited JSON-RPC on stdin/stdout; stderr-only logging) with concrete server + transport wiring.
Key content
- Protocol/transport constraints (stdio):
- MCP uses JSON-RPC 2.0; messages are newline-delimited over stdio.
- stdin: only MCP messages in. stdout: only MCP messages out. stderr: logging.
- Initialization lifecycle rule (critical):
- Before initialization completes, only
pingrequests and serverloggingnotifications are permitted; all other requests are forbidden until client sendsinitialized.
- Before initialization completes, only
- JSON-RPC message requirements (table):
- Request:
jsonrpc:"2.0", id required (string/number),methodrequired,paramsoptional. - Response:
jsonrpc:"2.0", id matches request, exactly one ofresultorerror. - Notification:
jsonrpc:"2.0",methodrequired, id forbidden.
- Request:
- Concrete stdio server procedure (TypeScript):
- Create
McpServer({ name, version }, { capabilities: { tools: { listChanged: false }}}). - Register a tool via
server.tool("greet", z.object({ name: z.string().min(1) }), async (input)=>({ content:[{type:"text", text:Hello, ${input.name}! Welcome to MCP.}] })). - Create transport:
const transport = new StdioServerTransport(); - Start:
await server.connect(transport);and log to stderr.
- Create
- Manual test command (exact):
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"greet","arguments":{"name":"World"}}}' | node build/index.js
- Defaults/parameters (project setup):
- Node target: ES2022, TS module: NodeNext, output dir
./build, root./src. - Example deps:
@modelcontextprotocol/sdk^1.11.0,zod^3.24.1.
- Node target: ES2022, TS module: NodeNext, output dir