Task statement 8.2 · Tools and MCPs
8.2 · MCP Server Development
Shelfwise, the course example, reaches its stock feed only through stock_mcp, a small Python MCP server whose one tool is stock_lookup. MCP server development decides what that server offers, how the agent reaches it, and where it runs.
share
The tempting design makes every capability an MCP tool and every server a web service. It fails because a tool lets the model decide when it is used, and a network endpoint adds sign-in and exposure that a server launched beside its one client never needed.
KnowledgeClient vs. server
MCP, the Model Context Protocol, has three roles. The host is the application that holds the conversation, such as Claude Code. Each client it creates exchanges JSON-RPC messages with one server. In revision 2026-07-28, current as of 2026-10-05, every request carries the client's capabilities, the optional features it supports, and server/discover returns the server's. Revisions up to 2025-11-25 negotiated them once, in an initialize handshake. In Shelfwise, the Agent SDK runs Claude Code as a subprocess that is host and client, and stock_mcp is the server.
KnowledgeServer authoring: tools, resources and prompts
Server authoring starts with choosing a primitive for each capability, because each one has a different controller. A server must advertise every primitive it implements. A tool is model-controlled, so Claude decides from its description when to call it. An MCP resource is application-controlled content at a URI, so the application or the user decides what reaches the model. An MCP prompt is a user-controlled template with arguments, usually started by typing a slash and its name.
Called with tools/call when its description fits. A failure is a normal result with isError set to true (8.1).
Listed with resources/list, read by URI, and attached by the host or picked by the user.
Fetched with prompts/get and arguments; Claude Code runs each as /mcp__server__prompt.
Official SDKs handle the protocol, with TypeScript, Python, C#, Go, Rust and Ruby in Tier 1. In Python, the MCPServer class, named FastMCP before SDK v2, turns a function's type hints and docstring into a definition. In TypeScript, McpServer offers registerTool.
KnowledgeCommunication patterns: stdio, Streamable HTTP and sockets
stdio (standard input and output) is the transport in which the client launches the server as a subprocess and the two exchange newline-delimited JSON-RPC messages over its stdin and stdout. The server may log to stderr, but it must write nothing to stdout except MCP messages, so a stray print() corrupts the stream. Streamable HTTP is the transport for a server running as its own process for many clients: the client POSTs each message to one MCP endpoint, and the server replies with JSON or an SSE stream scoped to that request (5.2). That server must check the Origin header to block DNS rebinding, a trick that lets a web page reach a local server.
Interactive · one tool call on each transport
Choose how the client reaches the server.
stdio: the client launches the server as its own subprocess and passes credentials in env. Each message is one line on stdin or stdout, so the server writes nothing else to stdout and logs to stderr. Closing stdin ends the server. Shelfwise's stock_mcp runs this way.
Streamable HTTP: the server is already running as a web service with one endpoint. Each message is its own POST with an access token, the server checks Origin and the token, and the reply is one JSON object or an SSE stream for that request only.
Custom transport over a socket: not one of the two standard transports. The specification says a Unix socket or TCP link should reuse stdio's one-message-per-line framing, and the transport should document how it connects and cancels. Both ends must support it.
More precise than the guide. The guide names "sockets", but specification revision 2026-07-28 defines only two standard transports, stdio and Streamable HTTP (as of 2026-10-05). A Unix domain socket or TCP connection can carry a custom transport, which should reuse stdio's newline-delimited framing. Claude Code's "type": "ws" WebSocket servers are also outside the standard (5.2). Exam answer: the standard transports are stdio and Streamable HTTP, and a socket carries a custom transport.
KnowledgeDeployment
Deployment follows the transport: a stdio server ships as a command that each host launches, and the specification tells it to take credentials from its environment. A Streamable HTTP server is a shared web service, so it should check callers. When it does, MCP authorization over HTTP is OAuth 2.1, with access tokens the client obtains for the user (7.4). Shelfwise's server shares the service's container, so the service launches it over stdio. Code declares it, because setting_sources=[] skips .mcp.json:
mcp_servers={"stock": {"command": "python", "args": ["-m", "stock_mcp"],
"env": {"STOCK_FEED_URL": os.environ["STOCK_FEED_URL"],
"STOCK_FEED_KEY": os.environ["STOCK_FEED_KEY"]}}}
KnowledgeIntegration with Claude applications
Integration differs in registration and in which primitives reach Claude. The Agent SDK names each tool mcp__<server>__<tool>, so Shelfwise's tool is mcp__stock__stock_lookup (1.2). The MCP connector gives a Messages API request a remote server's tools without an MCP client of your own.
The mcp_servers option takes stdio, HTTP, SSE or in-process sdk servers. Claude reads resources with built-in tools, which tools=[] removes.
Added with claude mcp add at local or project scope (7.4), or user scope, with resources by @server:protocol://path and prompts as commands.
Beta header mcp-client-2025-11-20, mcp_servers plus an mcp_toolset. Public HTTP servers and tool calls only.
Local stdio servers in claude_desktop_config.json, and remote ones as custom connectors whose resources and prompts attach to a message.
SkillWorked example: a feed check, tool or resource?
To see when the feed last updated while fixing its client, each engineer runs the server in Claude Code with claude mcp add stock --env STOCK_FEED_URL=… --env STOCK_FEED_KEY=… -- python -m stock_mcp. A draft added a second tool, feed_status. Claude's pull-request review flagged two costs in the service: the definition would join every request's cached ≈6,000-token prefix, and Claude could choose the tool in a staff chat. The cause was the primitive, because engineers, not Claude, decide when feed status matters:
mcp = MCPServer("stock") # Python SDK, run over stdio
@mcp.tool() # draft: Claude decides, in every chat
@mcp.resource("stock://feed-status") # merged: an engineer attaches it
def feed_status() -> str:
log.info("feed status read") # stderr; stdout carries only MCP
return f"feed {feed.time:%H:%M}, {feed.count} products"
An engineer now types @stock:stock://feed-status in Claude Code. Claude in the service cannot read the stock://feed-status resource, because tools=[] removes the tools that list and read resources, and stock_lookup stays the only definition in the prefix.
- A stdio server writes only MCP messages to stdout and its logs to stderr.
- The MCP connector uses only tools from public HTTP servers, while Claude Code and Claude Desktop also offer resources and prompts.
- Revision 2026-07-28 sends capabilities with every request, with an optional
server/discover. Revisions up to 2025-11-25, which the exam may assume, negotiate them once in aninitializehandshake.