Server primitives: tools, resources and prompts
Server primitives: tools, resources and prompts
If you watch the video: the workshop (kQmXtrmQ5Zg) section on the three primitives is still accurate on the idea of who controls each one. Treat the rest as legacy: it opens with an initialize handshake, and it presents sampling and roots as active features. Both are deprecated in 2026-07-28. It also does not cover structured output, isError, or list caching, which this lesson adds.
Where you are: Module 1, lesson 4. You know the roles (L03). Now you look at what a server exposes and what a correct definition and result look like in revision 2026-07-28.
What you will be able to do
- Choose between a tool, a resource and a prompt for a given capability, using the spec's control model.
- Read a
tools/listdefinition and atools/callresult, includingoutputSchema,structuredContentandisError. - Distinguish a tool execution error from a protocol error, and say which one the model should see.
- Explain why annotations are untrusted and what
ttlMs,cacheScopeand deterministic ordering are for.
Three primitives, three controllers
| Primitive | Controlled by | Methods | Typical use |
|---|---|---|---|
| Tool | the model ("model-controlled") | tools/list, tools/call | An action or computation: query an API, reserve stock |
| Resource | the application ("application-driven") | resources/list, resources/read, resources/templates/list | Read-only context identified by a URI: a file, a schema, an index |
| Prompt | the user ("user-controlled") | prompts/list, prompts/get | A template the user picks, often as a slash command |
The control split describes who decides when a primitive is used; it does not make a server safe. The protocol mandates no interaction model, and there SHOULD always be a human able to deny a tool invocation (L03). Safety comes from host consent plus validation, access control and least privilege in the server.
Resources may be picked by the user or included automatically "based on heuristics or the AI model's selection". Parameterised resources use URI templates (RFC 6570) from resources/templates/list. For prompts, "user-controlled" "refers to who decides when the prompt is used, not who authors its content."
Worked example: the notes server (lab-l08)
The lab-l08 server uses the official Python SDK (mcp 2.3.0, class MCPServer, the 2.x name for what 1.x called FastMCP). It exposes two tools, one resource and one prompt over stdio:
class Note(BaseModel):
id: str
title: str
body: str
tags: list[str]
@mcp.tool(name="get_note", title="Get a note by id",
annotations=ToolAnnotations(read_only_hint=True, open_world_hint=False))
def get_note(note_id: Annotated[str, Field(description="Note id such as N-001")]) -> Note:
"""Return one note by its id (format N-001)."""
if not re.fullmatch(NOTE_ID_PATTERN, note_id):
raise ToolError(f"Invalid note id {note_id!r}: expected the format N-001.")
...
@mcp.resource("notes://index", name="notes-index", mime_type="application/json")
def notes_index() -> str: ...
Because get_note returns a Pydantic model, the SDK publishes an outputSchema and returns structuredContent. Captured from the running server (trimmed):
{"name":"get_note","title":"Get a note by id",
"description":"Return one note by its id (format N-001).",
"inputSchema":{"type":"object","properties":{"note_id":{"type":"string","description":"Note id such as N-001"}},"required":["note_id"]},
"outputSchema":{"type":"object","properties":{"id":{"type":"string"},"title":{"type":"string"},"body":{"type":"string"},"tags":{"type":"array","items":{"type":"string"}}},"required":["id","title","body","tags"]},
"annotations":{"readOnlyHint":true,"openWorldHint":false}}
A successful call:
{"jsonrpc":"2.0","id":2,"result":{
"resultType":"complete","isError":false,
"content":[{"type":"text","text":"{\n \"id\": \"N-001\", ... }"}],
"structuredContent":{"id":"N-001","title":"Demo: buy cables","body":"Two demo USB-C cables.","tags":["demo","shopping"]}}}
Three rules from the tools page show up here:
- If a tool declares an
outputSchema, servers MUST return structured results that conform to it, and clients SHOULD validate them. - For backwards compatibility, a tool returning structured content SHOULD also return the serialised JSON in a text block. The SDK does this for you.
- Every result carries
resultType."complete"is a normal result;"input_required"means the server needs more input (L05). Clients MUST treat a missingresultTypefrom an older server as"complete".
Two kinds of error
The spec defines two mechanisms:
- Tool execution errors are results with
isError: true. Use them for API failures, invalid input values and business rules. Clients SHOULD pass them to the model so it can correct itself. - Protocol errors are JSON-RPC errors. The spec lists unknown tools, malformed requests and server errors, for example
{"code": -32602, "message": "Unknown tool: invalid_tool_name"}.
From the lab, a malformed id produces a correctable tool error:
{"jsonrpc":"2.0","id":3,"result":{"resultType":"complete","isError":true,
"content":[{"type":"text","text":"Error executing tool get_note: Invalid note id 'bad': expected the format N-001."}]}}
SDK behaviour worth knowing: in mcp 2.3.0, calling an unknown tool returned a result with isError: true and the text Unknown tool: nope, not a JSON-RPC -32602 error as in the spec's example. Clients should handle both shapes.
Tool definitions in more detail
- Names: SHOULD be 1 to 128 characters, case-sensitive, using only
A-Z a-z 0-9 _ - ., unique within the server. Hosts that combine servers SHOULD disambiguate collisions (for example by prefixing). inputSchema: MUST be a valid JSON Schema object (default dialect 2020-12). For no parameters the spec recommends{"type":"object","additionalProperties":false}.- Annotations: hints such as
readOnlyHint,destructiveHint,idempotentHint,openWorldHint. Clients MUST treat them as untrusted unless they come from trusted servers. resource_linkcontent: a tool may return a link instead of embedding data, for example{"type":"resource_link","uri":"file:///project/src/main.rs","name":"main.rs","mimeType":"text/x-rust"}. Linked resources need not appear inresources/list.- State: there is no protocol session (removed in 2026-07-28). A server that needs state across calls returns an explicit handle, such as a
basket_id, and accepts it on later calls; it must still check the caller's authorisation on every call.
Lists, caching and change notifications
List results, resources/read and server/discover carry ttlMs (a freshness hint in milliseconds) and cacheScope ("public" or "private"). Servers SHOULD return tools in a deterministic order, which helps client caching and prompt-cache hits. The lab's SDK sends ttlMs: 0, cacheScope: "private".
List sets MUST NOT vary per connection, but MAY vary by the authorisation on the request. Change notifications such as notifications/tools/list_changed now arrive only on a subscriptions/listen stream the client opens.
A missing resource returns -32602 in 2026-07-28 (-32002 in 2025-11-25; clients SHOULD still accept it). Servers MUST validate resource URIs and sanitise file paths against directory traversal.
Practice task
In the lab-l08 folder, send four requests by hand over stdio. Save this as requests.jsonl (each request on one line):
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_note","arguments":{"note_id":"N-001"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_note","arguments":{"note_id":"bad"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":4,"method":"resources/read","params":{"uri":"notes://index","_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
Then run: (cat requests.jsonl; sleep 3) | ./run.sh serve 2>/dev/null
The sleep keeps stdin open long enough for the replies; logs go to stderr and are hidden.
Check your result: four JSON lines come back, possibly not in order (match them by id). id 1 lists add_note and get_note, each with an outputSchema. id 2 has isError: false and a structuredContent object with "id":"N-001". id 3 has isError: true and the message about the format N-001. id 4 has a contents array with "uri":"notes://index" and mimeType application/json.
Check your understanding
-
You want the model to get the current database schema as background, but never change it. Tool or resource? A resource (for example
db://schema). It is read-only context the application can include, by user choice or automatically. A tool would be justified only if the model needs to choose parameters, such as one table out of thousands. -
A weather API returns HTTP 503 inside your tool. JSON-RPC error or
isError: true?isError: truewith a short, actionable message ("Weather service unavailable, try again later"). It is an execution error the model can reason about. JSON-RPC errors are for malformed requests, unknown tools and server faults. -
A third-party server declares
readOnlyHint: trueonwipe_cache. Your host auto-approves read-only tools. What is the problem? Annotations from an untrusted server are only claims. The spec says clients MUST treat them as untrusted unless the server is trusted. Auto-approval should be based on the user's trust in that server, not on its self-description.
Sources
- Tools: https://modelcontextprotocol.io/specification/2026-07-28/server/tools
- Resources: https://modelcontextprotocol.io/specification/2026-07-28/server/resources
- Prompts: https://modelcontextprotocol.io/specification/2026-07-28/server/prompts
- Base protocol (
resultType, error codes,_meta): https://modelcontextprotocol.io/specification/2026-07-28/basic - Changelog 2026-07-28: https://modelcontextprotocol.io/specification/2026-07-28/changelog
- Lab:
lab-l08/notes_server.py(outputs captured 2026-11-26 withmcp2.3.0)
