Build your own MCP server
Stage 3 of 5v1 · afc51c9e

Publish and invoke tools

Add discovery and validated execution for echo and add.

Build it in your language

The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.

Tool Discovery and Execution (tools/list and tools/call)

MCP tools let AI agents execute actions on the server via two endpoints:

  • tools/list: Discovers available tool schemas.
  • tools/call: Invokes a tool with specific parameters.

Mental Model: Tool Manifest and Invocation

  1. Manifest (tools/list):
    • "add": Takes numbers a and b.
    • "echo": Takes string text.
  2. Invocation (tools/call):
    • Evaluates arguments and returns results in a content array with isError: false.

Your Goal in this Stage

Implement tools/list for schema discovery and tools/call for execution.

Input Format (tools/list)

json
{ "jsonrpc": "2.0", "id": 3, "method": "tools/list" }

Output Format (tools/list)

json
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "tools": [
      {
        "name": "add",
        "description": "Add two numbers",
        "inputSchema": {
          "type": "object",
          "properties": {
            "a": { "type": "number" },
            "b": { "type": "number" }
          },
          "required": ["a", "b"],
          "additionalProperties": false
        }
      },
      {
        "name": "echo",
        "description": "Echo text",
        "inputSchema": {
          "type": "object",
          "properties": { "text": { "type": "string" } },
          "required": ["text"],
          "additionalProperties": false
        }
      }
    ]
  }
}

Input Format (tools/call)

json
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": { "name": "add", "arguments": { "a": 2.5, "b": 4 } }
}

Output Format (tools/call)

json
{
  "jsonrpc": "2.0",
  "id": 4,
  "result": { "content": [{ "type": "text", "text": "6.5" }], "isError": false }
}

Step-by-Step Implementation Guide

  1. Handle "tools/list": Return catalog with add and echo tool schemas.
  2. Handle "tools/call":
    • For add: add numbers and stringify sum.
    • For echo: stringify text argument.
  3. Emit output: Print JSON response with matching id.

Acceptance Criteria

  • ✅ Discloses add and echo schemas.
  • ✅ Correctly executes tool requests.

Output and errors

Multiline examples are formatted for readability. Emit compact JSON without optional spaces, with properties in the order shown by the output examples, and a final newline. Keep logs off stdout. Tests compare exact text.

Solutions

View solutions · Opens in a new tab