Build your own MCP server
Stage 4 of 5v1 · c1e1f8c9

Expose resources

List and read text resources by URI.

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.

Resource Provider (resources/list and resources/read)

MCP Resources offer read-only context addresses identified by custom URIs (such as memo://welcome).

Mental Model: Catalog and Read Endpoints

  • resources/list: Publishes available resource descriptors.
  • resources/read: Dispatches by URI and serves file/text contents.

Your Goal in this Stage

Implement resources/list and resources/read.

Input Format (resources/list)

json
{ "jsonrpc": "2.0", "id": 6, "method": "resources/list" }

Output Format (resources/list)

json
{
  "jsonrpc": "2.0",
  "id": 6,
  "result": {
    "resources": [
      {
        "uri": "memo://welcome",
        "name": "Welcome memo",
        "mimeType": "text/plain"
      }
    ]
  }
}

Input Format (resources/read)

json
{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "resources/read",
  "params": { "uri": "memo://welcome" }
}

Output Format (resources/read)

json
{
  "jsonrpc": "2.0",
  "id": 7,
  "result": {
    "contents": [
      {
        "uri": "memo://welcome",
        "mimeType": "text/plain",
        "text": "Welcome to Shipcode MCP."
      }
    ]
  }
}

Step-by-Step Implementation Guide

  1. Handle "resources/list": Return descriptor array containing memo://welcome.
  2. Handle "resources/read": Check URI matches memo://welcome and return payload contents.
  3. Emit output: Print JSON response with matching id.

Acceptance Criteria

  • ✅ Exposes resource catalog.
  • ✅ Reads resource text accurately.

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