Homework — Extend the PKB server
Lesson 04 · MCP Servers · Homework
You finished the lab with a single tool, echo, registered against the PKB server. The
three tasks below grow that surface area: a second tool, a tool with two arguments, and an
inspection of the JSON Schema FastMCP generated for you. Each task is independent — do them in
order, but you can pause between them.
Workflow reminder. After every edit to pkb/server.py: reinstall with
pip install -e . from mcp-servers/sample-server/python, then fully
Quit Claude Desktop (Cmd-Q on macOS) and reopen it. Closing the window is not
enough — the config and tool list are only read at process start.
Task 1 — Add a second tool: reverse
In pkb/server.py, add a second tool below echo that reverses the input
message:
@mcp.tool()
def reverse(message: str) -> str:
"""Return the message with characters reversed."""
return message[::-1]
Then:
- Reinstall the package:
pip install -e .frommcp-servers/sample-server/python. - Fully Quit and reopen Claude Desktop.
- In a fresh chat, ask Claude to use the new tool — for example: "use pkb.reverse on the string hello".
- Approve the tool permission prompt if it appears.
✓ Self-check: take a screenshot of Claude calling reverse with
input "hello" and showing the result "olleh" in the tool result panel.
Task 2 — Tool with two arguments: repeat
Add a third tool that takes two arguments — a string and an integer — and returns the string
repeated n times:
@mcp.tool()
def repeat(message: str, n: int) -> str:
"""Return the message repeated n times."""
return message * n
Reinstall, restart Claude Desktop, and then open the MCP Inspector with
mcp dev pkb/server.py from a separate terminal. In the Inspector:
- Open the Tools tab.
- Click
repeatand look at the form on the right — bothmessageandnshould appear as required fields, with the correct types (stringandinteger). - Call the tool with
{"message": "ab", "n": 3}.
✓ Self-check: the Inspector shows repeat with both
message and n in its schema, and calling it with
{message: "ab", n: 3} returns the string "ababab".
Task 3 — What the LLM sees: capture the echo JSON Schema
Claude does not see your Python source — it sees a JSON Schema built from your function signature. In this task you capture exactly what the model receives.
- Start the Inspector:
mcp dev pkb/server.py. - Open the Tools tab and click on the
echotool. - Find the JSON Schema FastMCP generated for it (the Inspector exposes it as the tool's
inputSchema). Copy the schema verbatim into your homework writeup.
As you paste the schema, note two things:
- The description on the tool comes from the function's docstring ("Echo the message back.").
- The type under
properties.message.typecomes from themessage: strtype hint.
✓ Self-check: your pasted schema has exactly
"required": ["message"] and
properties.message.type equal to "string".