Build your own MCP server
Stage 2 of 5v2 · a3b31b17

Negotiate the MCP session

Implement initialize and advertise server identity and capabilities.

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.

MCP Handshake (Initialize Negotiation)

Before calling tools, an MCP client initiates an exchange via initialize to negotiate protocol versions and discover capabilities.

Mental Model: Initialize Handshake

  1. Initialize Request: Supplies protocolVersion, capabilities, and clientInfo.
  2. Initialize Response:
    • Echoes protocolVersion: "2025-06-18".
    • Declares capabilities: {"tools": {}, "resources": {}}.
    • Identifies server via serverInfo: {"name": "shipcode-mcp", "version": "1.0.0"}.

Your Goal in this Stage

Handle "initialize" requests and return server capability metadata.

Input Format

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-06-18",
    "capabilities": {},
    "clientInfo": { "name": "tests", "version": "1" }
  }
}

Output Format

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-06-18",
    "capabilities": { "tools": {}, "resources": {} },
    "serverInfo": { "name": "shipcode-mcp", "version": "1.0.0" }
  }
}

Step-by-Step Implementation Guide

  1. Match "initialize" method:
  2. Assemble response result:
    • protocolVersion: "2025-06-18"
    • capabilities: { tools: {}, resources: {} }
    • serverInfo: { name: "shipcode-mcp", version: "1.0.0" }
  3. Emit output: Print JSON response with matching id.

Acceptance Criteria

  • ✅ Returns standard MCP initialize payload.
  • ✅ Preserves ping capability.

Supported version

This project implements 2025-06-18. Return it when requested and offer it when a different version is requested. Do not echo an unsupported version. The client decides whether to accept the alternative. After the handshake it sends notifications/initialized, which produces no response. Exit cleanly at EOF.

MCP lifecycle.

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