Your own MCP server in Jennifer

Jennifer

A small server that serves the Jennifer documentation to an assistant: two tools, every page as a resource and a prompt, tested with real clients and connected to Claude™ Code and VS Code™.

November 2026, by @mplx.
Based on Jennifer 0.27.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 20

MCP in one slide

RoleWhat it isExample
Hostthe application the user talks toClaude Code, VS Code
Clientone connection inside the hostone per server
Servera program that offers contextdocs.j
2 / 20

What goes over the wire

-> {"method":"initialize","params":{"protocolVersion":"2025-11-25",...
<- {"result":{"protocolVersion":"2025-06-18","capabilities":
     {"tools":{},"resources":{},"prompts":{}},
     "serverInfo":{"name":"jennifer-docs","version":"0.1.0"}},"id":0}
-> {"method":"notifications/initialized"}
-> {"method":"tools/list","id":1}
<- {"result":{"tools":[{"name":"search_docs",...}]},"id":1}
-> {"method":"tools/call","params":{"name":"search_docs",
     "arguments":{"query":"path.clean"}},"id":2}
<- {"result":{"content":[{"type":"text","text":"docs://libraries/
     path.md (2x) ## Functions\n..."}],"isError":false},"id":2}
3 / 20

The mcp module in 0.26.0

4 / 20

The sample: a documentation server

KindNameWhat it gives
toolsearch_docs(query)pages that mention a phrase, a line each
toolread_doc(path)one page as Markdown
resourcedocs://libraries/json.md, ...every page, 168 of them
promptexplain_function(name)"explain json.decode from the docs"
jennifer run docs.j ~/src/jennifer/docs     # read-only, stdio
5 / 20

Start-up: the root and the page list

# os.ARGS[1]: exactly one argument, a directory, or exit 2
def root as string init fs.realpath(os.ARGS[1]);

func docPages() {
    def found as list of string init [];
    for (def st in fs.walk($root)) {
        if (not $st.isDir and strings.endsWith($st.path, ".md")) {
            $found[] = $st.path[len($root) + 1..];
        }
    }
    return lists.sort($found);
}
def pages as list of string init docPages();
6 / 20

search_docs: one tool handler

func searchDocs(args as json.Value) {
    def q as string init strings.lower(
        requireString($args, "query", 100));
    def hits as list of Hit init [];
    for (def p in $pages) {
        def text as string init fs.readString($root + "/" + $p);
        def n as int init strings.count(strings.lower($text), $q);
        if ($n > 0) {
            $hits[] = firstHit($p, $text, $q, $n);
        }
    }
    # ... most hits first, the first 8 as lines of text ...
}
7 / 20

read_doc: only pages from the list

func readDoc(args as json.Value) {
    def p as string init strings.replace(
        requireString($args, "path", 200), "docs://", "");
    if (not lists.contains($pages, $p)) {
        return "No such page: " + $p + ". Use search_docs to find one.";
    }
    return fs.readString($root + "/" + $p);
}
read_doc ../../../etc/passwd -> No such page: ../../../etc/passwd. ...
read_doc /etc/passwd         -> No such page: /etc/passwd. ...
8 / 20

Register it, serve it

def q as json.Value init mcp.property(mcp.schema(), "query",
    "string",
    "a word or phrase, 2 to 100 characters, such as json.decode",
    true);
def s as mcp.Server init mcp.server("jennifer-docs", "0.1.0");
$s = mcp.addTool($s, "search_docs",
    "Search the Jennifer language documentation. Use it before " +
    "answering a question about a Jennifer library, module or " +
    "function. Returns page paths with a matching line.",
    $q, searchDocs);
mcp.serveStdio($s);
9 / 20

Resources: every page

func readResource(uri as json.Value) {
    def p as string init json.asString($uri, "")[7..];
    return fs.readString($root + "/" + $p);
}
# in docsServer():
for (def p in $pages) {
    $s = mcp.addResource($s, "docs://" + $p, $p,
        "Jennifer docs: " + $p, "text/markdown", readResource);
}
resources/list                          -> 168, docs://SUMMARY.md first
resources/read docs://../../etc/passwd  -> -32602 "Resource not found"
10 / 20

A prompt: explain_function

func explainFunction(args as json.Value) {
    def name as string init requireString($args, "name", 60);
    if (not regex.matches(
        "^[a-z][a-zA-Z0-9]*\\.[a-zA-Z][a-zA-Z0-9]*$", $name)) {
        throw Error{kind: "value", message: "name: lib.function"};
    }
    def text as string init "Explain the Jennifer function " +
        $name + ". Use the search_docs and read_doc tools; ...";
    def msg as json.Value init json.decode(
        '{"role":"user","content":{"type":"text","text":""}}');
    $msg = json.set($msg, "/content/text", $text);
    return json.append(json.list(), "", $msg);
}
11 / 20

Testing with the module's own client

def c as mcp.Client init mcp.connectStdio(
    ["jennifer", "run", "docs.j", os.ARGS[1]]);
def a as json.Value init json.set(json.map(), "/query", "realpath");
def out as json.Value init mcp.callTool($c, "search_docs", $a);
io.printf("%s\n", json.asString($out, "/content/0/text"));
docs://libraries/fs.md (4x) ## Metadata
    | `fs.realpath(path)` | `string`  | Absolute, symlink-resolved...
docs://libraries/cheatsheet.md (2x) ## Functions
    | [`fs`](fs.md)`.realpath(path)`                        | Absolu...
matching pages: 2; read one with read_doc.
12 / 20

Testing with the official Inspector

npx -y @modelcontextprotocol/inspector@2.14.0 --cli \
    jennifer run docs.j ~/src/jennifer/docs \
    --method tools/call --tool-name search_docs --tool-arg query=x
{ "content": [ { "type": "text", "text": "Tool execution failed" } ],
  "isError": true }
13 / 20

Claude Code: add the server

claude mcp add -s project jennifer-docs -- \
    jennifer run /opt/jennifer-docs/docs.j /srv/jennifer/docs
{ "mcpServers": { "jennifer-docs": {
    "type": "stdio", "command": "jennifer",
    "args": ["run", "/opt/jennifer-docs/docs.j", "/srv/jennifer/docs"],
    "env": {} } } }

-s local (default): you, this project; project: .mcp.json, shared through git; user: you, every project.

14 / 20

Claude Code: approve, then ask

$ claude mcp get jennifer-docs
  Scope: Project config (shared via .mcp.json)
  Status: Pending approval (run `claude` to approve)
$ claude -p "Which Jennifer function compares two byte strings in
    constant time, and what does it return? ..." \
    --mcp-config .mcp.json --allowedTools mcp__jennifer-docs__...
search_docs {"query":"constant time"}
search_docs {"query":"hash.equal"}
read_doc    {"path":"libraries/hash.md"}
The function is `hash.equal(a, b)` from the `hash` library ...
15 / 20

VS Code

{
    "mcpServers": {
        "jennifer-docs": {
            "type": "stdio",
            "command": "jennifer",
            "args": ["run", "/opt/jennifer-docs/docs.j",
                     "/srv/jennifer/docs"],
            "tools": ["*"]
        }
    }
}
16 / 20

Streamable HTTP, the stateless way

func postMcp(ctx as web.Context) {
    # ... Origin and bearer token checks, next slide ...
    def body as string init encoding.decode("utf-8",
        web.body($ctx));
    def reply as string init mcp.handle($srv, $body);
    if ($reply == "") {
        web.respond($ctx, 202, "");      # a notification
        return;
    }
    web.setHeader($ctx, "Content-Type", "application/json");
    web.respond($ctx, 200, $reply);
}

POST /mcp answers with JSON; GET /mcp with 405: no event stream.

17 / 20

Authentication, and why it matters

def origin as string init web.header($ctx, "Origin");
if ($origin != "" and $origin != ORIGIN) {
    web.text($ctx, 403, "origin not allowed\n");
    return;
}
if (not hash.equal(utf8(web.bearerToken($ctx)), utf8($token))) {
    web.setHeader($ctx, "WWW-Authenticate", "Bearer");
    web.text($ctx, 401, "bearer token required\n");
    return;
}
token: 2 matching pages | wrong token: RpcError, status 401
no token (Inspector): auth_required | other Origin: 403
18 / 20

Security: a tool runs with your rights

19 / 20

Read more

Based on Jennifer 0.27.0, November 2026.

20 / 20