Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
Build one small SupportDesk MCP server that offers a tool, a resource and a prompt, written in Python and in TypeScript, and check both with the same real MCP client.
What you will learn
- Explain what an MCP server offers and who controls each of its three kinds of things
- Write a small MCP server with one tool, one resource and one prompt in Python and TypeScript
- List and use a server's tools, resources and prompts from a real MCP client
- Decide whether a capability should be a tool, a resource or a prompt
Before you start
- Claude tool use: tool_use and tool_result
- Basic Python
Picture a support team with its own orders and its own returns policy. A chat app wants that data. So does the support console, and so does the team bot. Without a shared standard, each app gets its own glue code, and you write the same connector three times.
The Model Context Protocol (MCP) fixes that. You write one MCP server that sits next to the data, and any app that speaks MCP can connect to it. In this article we build that server, called supportdesk, once in Python and once in TypeScript, and check both with the same client.
Where the server sits
An app (Claude Code, Claude Desktop or your own program) holds an MCP client. The part we build is the server. A request goes down: the client sends a tools/call with an order id. The answer comes back up: the server returns the status text and the client hands it to the app.
The server decides what it offers. The client only asks.
Three kinds of things, three controllers
Think of the front desk of a help office. It has a filing cabinet you open and read, a service counter where you ask and someone does the job, and a pre-printed form you pick and fill in. In MCP those are a resource, a tool and a prompt. The difference that matters is who decides to use each one.
| Kind | What it is | Who decides | Python | Calls |
|---|---|---|---|---|
| Tool | Something that does a job | The model calls it | @mcp.tool() | tools/list, tools/call |
| Resource | Content at a URI, to read | The app attaches it | @mcp.resource(uri) | resources/list, resources/read |
| Prompt | A ready-made request | The user picks it | @mcp.prompt() | prompts/list, prompts/get |
Each kind has a list call and a use call. The server only declares them; control sits with the model, the app or the user.
server.py: the whole server
Here is the complete Python server. Two made-up records stand in for the real data.
"""SupportDesk MCP server: one tool, one resource, one prompt, over stdio."""
from mcp.server import MCPServer
mcp = MCPServer("supportdesk")
ORDERS = {"A-1001": "shipped, arrives Friday"}
RETURNS = "Returns are accepted for 30 days if the item is unused."
@mcp.tool()
def order_status(order_id: str) -> str:
"""Look up the delivery status of one order by its id."""
return ORDERS.get(order_id, "unknown order")
@mcp.resource("policy://returns")
def returns_policy() -> str:
"""The returns policy text."""
return RETURNS
@mcp.prompt()
def ticket_summary(ticket_id: str) -> str:
"""A ready-made request: summarise one ticket."""
return f"Summarise {ticket_id}."
if __name__ == "__main__":
mcp.run(transport="stdio")
- One server object with a name,
supportdesk. - The tool decorator turns a plain function into something the model can call.
- The resource has a URI,
policy://returns, and returns the policy text. - The prompt takes a ticket id and returns a ready-made request.
- The last line runs the server over standard input and output, so a client can start it as a process. The two transports get their own article.
The code writes the tool definition
The tool you just wrote is also a tool definition for Claude. The function name becomes the tool name, the docstring becomes the description, and the typed argument becomes the input_schema. Those are the same three fields you pass in the Messages API (see Claude tool use: tool_use and tool_result).
So the quality of the docstring is not a style point. It is the text Claude reads when it chooses a tool. A clear name, a clear docstring and a typed argument decide how well the model picks.
server.ts: the same server in TypeScript
Same three things with the TypeScript SDK. The input and argument schemas are zod objects.
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";
const server = new McpServer({ name: "supportdesk", version: "1.0.0" });
const ORDERS: Record<string, string> = { "A-1001": "shipped, arrives Friday" };
const RETURNS = "Returns are accepted for 30 days if the item is unused.";
server.registerTool(
"order_status",
{
description: "Look up the delivery status of one order by its id.",
inputSchema: z.object({ order_id: z.string() }),
},
async ({ order_id }) => ({
content: [{ type: "text", text: ORDERS[order_id] ?? "unknown order" }],
}),
);
server.registerResource(
"returns_policy",
"policy://returns",
{ description: "The returns policy text.", mimeType: "text/plain" },
async (uri) => ({ contents: [{ uri: uri.href, text: RETURNS }] }),
);
server.registerPrompt(
"ticket_summary",
{
description: "A ready-made request: summarise one ticket.",
argsSchema: z.object({ ticket_id: z.string() }),
},
({ ticket_id }) => ({
messages: [
{ role: "user", content: { type: "text", text: `Summarise ${ticket_id}.` } },
],
}),
);
await server.connect(new StdioServerTransport());
registerTool, registerResource and registerPrompt mirror the three Python decorators, and connect attaches the stdio transport.
A client lists, then uses
Now a real MCP client starts each server as a subprocess and talks to it. No model and no API key are involved. This is the core of client_check.py:
async with Client(StdioServerParameters(command=command, args=args, cwd=cwd)) as client:
print(f"{label} server: {client.server_info.name}")
for t in (await client.list_tools()).tools:
print(f"tool {t.name} {sorted(t.input_schema['properties'])}")
for r in (await client.list_resources()).resources:
print(f"resource {r.uri}")
for p in (await client.list_prompts()).prompts:
print(f"prompt {p.name} {[a.name for a in p.arguments]}")
first = (await client.list_tools()).tools[0]
claude_tool = {"name": first.name, "description": first.description, "input_schema": first.input_schema}
print("for Claude ->", sorted(claude_tool))
done = await client.call_tool("order_status", {"order_id": "A-1001"})
print("call tool ->", done.content[0].text)
read = await client.read_resource("policy://returns")
print("read resource ->", read.contents[0].text)
got = await client.get_prompt("ticket_summary", {"ticket_id": "T-204"})
print("get prompt ->", got.messages[0].content.text)
run_all.py checks the Python server, then the TypeScript server, with the very same client:
python server: supportdesk
tool order_status ['order_id']
resource policy://returns
prompt ticket_summary ['ticket_id']
for Claude -> ['description', 'input_schema', 'name']
call tool -> shipped, arrives Friday
read resource -> Returns are accepted for 30 days if the item is unused.
get prompt -> Summarise T-204.
typescript server: supportdesk
tool order_status ['order_id']
resource policy://returns
prompt ticket_summary ['ticket_id']
for Claude -> ['description', 'input_schema', 'name']
call tool -> shipped, arrives Friday
read resource -> Returns are accepted for 30 days if the item is unused.
get prompt -> Summarise T-204.
The two blocks are identical. To the client, it is the same server. And the for Claude line shows the three fields ready to hand to Claude as a tool.
Which of the three fits the job
Say a team wants every app to look up orders and to read the returns policy. Three tempting answers fail:
- Paste the policy into every prompt. The copies go stale, and every request carries the extra text.
- Write a connector inside each app. The same work, again and again.
- Make everything a tool. The model then has to call a tool just to read text.
The answer is one MCP server. The lookup is a tool, because it does something. The policy is a resource, because it is content to read. A request the user starts from, like "summarise this ticket", is a prompt.
The same rule covers a catalog. If an agent keeps calling a "list SKUs" tool before every answer just to learn what exists, expose that list as a resource it reads once. Exploratory tool calls go away, and nothing gets pasted into system prompts.
Common mistakes
- A vague docstring. It becomes the tool description Claude reads, so "gets stock" on two tools makes the model guess.
- Reading content through a tool. Fixed text belongs in a resource the app can attach.
- Hiding a write in a resource. Resources are for reading. An action that changes data is a tool, and an approval step in the client goes in front of it.
- Writing glue per app. If three apps need the same data, that is the signal for one server.
Recap
| Idea | In practice |
|---|---|
| Server declares, client asks | List first, then use: the same calls work for any server |
| Tool | The model calls it; name, docstring and typed args become the tool definition |
| Resource | The app reads it by URI |
| Prompt | The user picks it and fills in the arguments |
| stdio | The client starts the server as a local process |
Try it yourself: add a second resource, policy://shipping, to both servers and check that the client lists it on both. The server files and the client are in the community, free to join.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
A support agent forgets the customer's name, order and contact choice after twenty turns and fails 0 of 4 checks. Measure the window, clear old tool output, compact old turns and keep a notes file, and the same chat passes 4 of 4 with 470 tokens instead of 2,945.
What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table
LangChain is a box of standard parts (models, prompts, retrievers, tools, parsers) that snap together with a pipe. The same refund question through the plain Anthropic SDK (1 import, 13 lines) and a chain (3 imports, 14 lines) gives the same answer word for word. It pays off when the bot grows; for one call, the SDK is simpler, with 16 packages instead of 38.
Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph
A refund assistant built three ways. The chain runs classify, retrieve, reply once: it answers an opening-hours question with the billing line, misses the 30-day window, and sends a $150 refund with approved False. Plain if/while fixes it but hides the flow; a LangGraph StateGraph puts the branch, the retry loop and the approval stop in the arrows.
LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways
Two small graphs. A refund skeleton: SupportState, a classify node, a route function on a conditional edge, and an Annotated log that appends instead of overwriting. A help desk: classify and answer call a scripted test model, spam goes straight to END after one model call instead of two, and the same run read with invoke, stream values and stream updates.