mjdi

Search documentation

Search the mjdi v0.10.0 documentation

mjdi docsv0.10.0latest

MCP server

The mjdi repository ships a documentation website (website/, a Next.js

Source: mjdi/docs/mcp-server.md

The mjdi repository ships a documentation website (website/, a Next.js application). One of its API routes is an MCP endpoint — a Model Context Protocol server that exposes this entire documentation set and the example sources to MCP-capable clients (editors, coding agents, MCP inspectors).

This document describes the implemented, tested behavior of that endpoint. Every request and response shown below was executed against the shipped implementation.

  • Endpoint path: /api/mcp (same origin as the website)
  • Implementation: website/src/app/api/mcp/route.ts
  • Transport: MCP Streamable HTTP — JSON-RPC 2.0 over HTTP POST
  • Server identity: mjdi-docs, version matches the repository release
  • Version-aware: documentation tools accept an optional version argument and resources are addressed per version (see the website versioning model)
  • Read-only: the server never mutates anything; it serves documentation text

1. Transport and protocol

1.1 Streamable HTTP, stateless

Every POST carries exactly one JSON-RPC 2.0 message (or a batch array) and receives either:

  • 200 OK with application/json — the JSON-RPC response,
  • 202 Accepted with an empty body — the message was a known notification (notifications produce no response),
  • 400 Bad Request — the body was not valid JSON or not a JSON-RPC message (only for a malformed single message).

The server is stateless:

PropertyBehavior
SessionsNone are issued. Mcp-Session-Id is accepted and ignored.
GET405 Method Not Allowed with a JSON-RPC error body — no SSE stream.
DELETE405 Method Not Allowed — nothing to terminate.
OPTIONS204 No Content with permissive CORS headers.
CORSAccess-Control-Allow-Origin: * on every response.
BatchingA JSON array body is answered with an array of responses, in order.

1.2 Protocol version negotiation

initialize echoes the client's protocolVersion when the server supports it, otherwise falls back to the server's latest:

Client requestsServer negotiates
2025-06-182025-06-18
2025-03-262025-03-26
2024-11-052024-11-05
anything else / omitted2025-06-18

1.3 Handshake

curl -X POST https://<host>/api/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{
        "protocolVersion":"2025-06-18","capabilities":{},
        "clientInfo":{"name":"my-client","version":"1.0"}}}'

Response (truncated):

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-06-18",
    "capabilities": {
      "tools": { "listChanged": false },
      "resources": { "subscribe": false, "listChanged": false }
    },
    "serverInfo": {
      "name": "mjdi-docs",
      "title": "mjdi documentation server",
      "version": "0.5.0"
    },
    "instructions": "Documentation and examples for mjdi 0.5.0, the compile-time-first dependency injection library for Mojo 1.2.0. ..."
  }
}

Afterwards send the standard notifications/initialized notification — it is answered with 202 Accepted and no body:

curl -X POST https://<host>/api/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'

2. Methods

MethodResult
initializeProtocol version, capabilities, server info, usage instructions.
notifications/initializedAccepted (202), no response.
pingEmpty object {}.
tools/listThe fourteen tools of section 3.
tools/callRuns one tool; result is a content array with a single text block.
resources/listEvery documentation page of every served version as mjdi://docs/<version>/<slug> resources.
resources/readReturns one page as text/markdown; versioned URIs and the legacy unversioned form both resolve.
resources/templates/listEmpty (all resources are concrete).
prompts/listEmpty (no prompts).
anything elseJSON-RPC error -32601 with the list of supported methods in data.supported.

3. Tools

All tools return a single text content block. Structured payloads (doc lists, search hits, examples) are pretty-printed JSON inside that text; documents are returned as their raw markdown. Tool-level problems (unknown slug, unknown version, too-short query) set isError: true and explain the fix in the text — they are not protocol errors.

Every documentation tool takes an optional version argument (an exact version like "0.5.0" or "0.4.0"; omitted or "latest" resolves to the current release). Call list_doc_versions first when release pinning matters.

3.1 list_doc_versions

No arguments. Returns every served documentation version with its status ("latest" or "archived"), released date, release title, the URL layout for pages and raw markdown, and the resource-URI pattern:

{
  "version": "0.4.0",
  "status": "archived",
  "released": "2026-11-19",
  "title": "Third-party structures",
  "pages_url": "/docs/0.4.0/index",
  "raw_markdown_url": "/api/docs/0.4.0/<page>.md",
  "resource_uri": "mjdi://docs/0.4.0/<page>"
}

3.2 list_docs

Arguments: version (string, optional). Returns every documentation page of that version grouped by the same sections the website sidebar uses (Start here, Everyday use, Scopes and memory, Correctness, Testing and examples, Reference), each entry with slug, title and a one-line description. Start here before calling get_doc.

3.3 get_doc

Arguments: slug (string, required), version (string, optional). Returns the full markdown of that version's docs/<slug>.md. Unknown slugs or versions produce an isError: true result that lists the remedy: "Call list_docs (optionally with that version) for valid slugs." Archived versions only contain the pages they shipped.

3.4 search_docs

Arguments: query (string, required, minimum 2 characters), version (string, optional), limit (number, optional, 1–50, default 12). Full-text search across one version's pages. Each hit reports slug, title, a snippet, and where the match was found: "title", "heading", or "body" (first matching non-heading line). Title matches rank first, then heading matches, then body matches.

3.5 get_quickstart

Arguments: version (string, optional). Returns that version's docs/getting-started.md — install Mojo, add mjdi, the first wired program, run the examples and the test suite.

3.6 get_api_reference

Arguments: version (string, optional). Returns that version's docs/api-reference.md — every public symbol with signatures, bounds, and semantics.

3.7 get_changelog

Arguments: version (string, optional). Returns that version's docs/changelog.md — the release history exactly as the release shipped it (an archived version's changelog describes its own release as current).

3.8 list_examples

No arguments. Returns the ten example applications with their directory name and a one-line description extracted from the first comment line of each examples/<name>/app.mojo. Examples always reflect the current repository state (they are not versioned snapshots).

3.9 get_example

Arguments: name (string, required). Returns the full Mojo source of examples/<name>/app.mojo. Names must match [a-z0-9_]+; anything else is rejected before it can touch the filesystem.

Example call and response:

curl -X POST https://<host>/api/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{
        "name":"get_example","arguments":{"name":"basic_wiring"}}}'
{
  "jsonrpc": "2.0",
  "id": 4,
  "result": {
    "content": [{ "type": "text", "text": "# ===--- ... Example 01: basic automatic wiring. ..." }],
    "isError": false
  }
}

3.10 diagnostics_lookup (P2-14)

Arguments: query (string, required — a stable diagnostic ID like "MJDI-E001", case-insensitive, or a search term over id/title/cause, minimum 2 characters), limit (number, optional, default 10, max 25). Returns the matching diagnostics/catalog.json entries — id, title, severity, stage, cause, quick fix, bad/good snippets, docs links — plus any retired IDs the query touches (retired IDs are never renumbered and never match as entries). Read-only; deterministic; the result names the generator the catalog came from.

3.11 symbol_lookup (P2-14)

Arguments: symbol (string, required — a Mojo identifier), version (optional). Returns the exact section of the generated API reference that documents the symbol (the ### <symbol> heading through the next heading) and the list of documentation pages that mention it, for the requested version. Unknown symbols return found: false with the mentions still listed. Read-only.

3.12 example_search (P2-14)

Arguments: query (string, required, minimum 2 characters), limit (number, optional, default 8). A plain case-insensitive substring search — no regex from the client — over every example's description and source. Returns each hit with the matched lines and line numbers so clients can jump into get_example. Deterministic. Read-only.

3.13 release_notes_lookup (P2-14)

Arguments: version (optional, defaults to the latest release). Returns that release's changelog section exactly as it shipped, plus the release metadata (date, title, archive status) and the raw-markdown URL. Read-only.

3.14 graph_validate (P2-14)

Arguments: graph (string, required — a mjdi.graph/1 JSON export from graph_json[registry](), or Graphviz DOT from graph_dot[registry](), maximum 256 KiB). Validates the artifact structurally: schema string, node/edge object shapes, referential integrity (every edge endpoint must be a known service), cycle detection over the edge set, and, for DOT, balanced braces and statement presence. Returns valid, the detected format, node/edge counts, the service list, the detected cycles, and problems with actionable path/message pairs.

Graph ingestion is inspection, not execution: the artifact is parsed and validated in memory; nothing in it is executed, nothing is stored (the endpoint is stateless), and oversize or malformed input is rejected before parsing. The request body itself is capped at the transport layer (see the security posture review).

4. Resources

Every documentation page of every served version is also an MCP resource, addressed by a versioned URI:

FieldValue
URI schememjdi://docs/<version>/<slug> — one concrete URI per page per version (0.5.0's 25 pages plus 0.4.0's 23)
nameThe page title from that version's documentation nav
descriptionThe page's first-paragraph summary
mimeTypetext/markdown

The legacy unversioned form mjdi://docs/<slug> still resolves — it reads the page from the latest version — so clients written against the previous endpoint keep working.

resources/read with {"uri":"mjdi://docs/0.4.0/api-reference"} returns contents: [{ uri, mimeType: "text/markdown", text }]. Malformed or unknown URIs are protocol errors (-32602), with the expected shape in data.expected; an unknown version reports data.available.

5. Error model

CodeMeaningWhen
-32700Parse errorBody is not valid JSON. HTTP 400.
-32600Invalid requestBody is not a JSON-RPC 2.0 message; empty batch.
-32601Method not foundUnknown method or unsupported notification.
-32602Invalid paramsMalformed tool arguments schema, unknown tool, bad resource URI.
-32603Internal errorUnexpected failure inside a handler.

Error responses echo the request id. Protocol-level errors carry structured data where useful (for example data.available for an unknown tool, data.supported for an unknown method). Tool-level failures are results with isError: true so clients can display them without treating the transport as broken.

Every JSON-RPC response's id equals the request's id, including in batches — response order matches request order.

6. Connecting an MCP client

Most MCP clients register remote Streamable-HTTP servers in their configuration:

{
  "mcpServers": {
    "mjdi-docs": {
      "type": "http",
      "url": "https://<host>/api/mcp"
    }
  }
}

There is no authentication: the endpoint is a public, read-only mirror of the repository documentation. The website landing page includes an interactive playground that speaks this exact protocol, useful for inspecting tools and resources without a client.

7. Scope and boundaries

  • The server is read-only. It performs no writes, spawns no processes, and executes no Mojo code.
  • The served text comes straight from docs/*.md and examples/*/*.mojo at request time — there is no build step or copy that can drift from the repository.
  • There is no SSE stream, no change subscription, and no session state; clients that require stdio can wrap the HTTP endpoint with any stdio-to-HTTP bridge.
  • The endpoint is part of the website (website/), not part of the Mojo library; it has no effect on mjdi/*.mojo or its test suite.

8. Verifying the endpoint

The behavior above was verified with a curl suite covering: the handshake, notification acceptance (202), ping, tools/list (all fourteen tools present), every tool call including the versioned calls (get_doc with "version":"0.4.0"), the isError paths (unknown slug, unknown version, too-short query), resource listing and reading (versioned URIs, the legacy unversioned alias, and an unknown version), unknown tool (-32602), unknown method (-32601), parse error (-32700 with HTTP 400), protocol-version negotiation for all three supported versions, batch requests with correct id echo, GET/DELETE rejection (405), and the CORS preflight (204).

The versioned website surface is verified separately (see docs-website.md): version redirects, archived-snapshot pages, raw markdown endpoints, the bundle route and /llms.txt.