Lesson 04 Your First MCP Server
Theme:

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:

  1. Reinstall the package: pip install -e . from mcp-servers/sample-server/python.
  2. Fully Quit and reopen Claude Desktop.
  3. In a fresh chat, ask Claude to use the new tool — for example: "use pkb.reverse on the string hello".
  4. 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:

  1. Open the Tools tab.
  2. Click repeat and look at the form on the right — both message and n should appear as required fields, with the correct types (string and integer).
  3. 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.

  1. Start the Inspector: mcp dev pkb/server.py.
  2. Open the Tools tab and click on the echo tool.
  3. 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:

✓ Self-check: your pasted schema has exactly "required": ["message"] and properties.message.type equal to "string".

View solutions →