Skip to main content
Glama
mcp-jobs-server

mcp-jobs-server

by fvonhoven
README.md
# mcp-jobs-server

## What this is

A Model Context Protocol (MCP) server that exposes a React Native + AI jobs board to Claude Desktop, Claude Code, or any other MCP client, written by hand over stdio JSON-RPC with zero dependencies. It ships 40 fictional job postings, five tools, two resource types, one prompt, a tiny client, and tests that drive the real server as a child process.

## The problem it solves

An LLM can only act on what is in its context window. MCP is the wire protocol that lets a model host (Claude Desktop, an IDE, an agent runtime) discover and call capabilities a server offers: tools it can invoke, resources it can read, and prompt templates it can offer the user. Every "connect Claude to X" integration is an MCP server underneath.

Most people meet MCP through the official SDK, which hides the protocol. That is fine for shipping, and bad for understanding. This repo implements the protocol directly so the messages are visible: what `initialize` returns, how a tool advertises its schema, what a JSON-RPC error looks like versus a tool failure, and why the server must never print to stdout. Once you have seen all of that once, the SDK stops being magic.

The data source is a jobs board for React Native and AI roles (the author runs reactnativeaijobs.com). The postings in `data/jobs.json` are invented; every company name is fictional and every apply URL points at example.com.

## How it works

```
client (Claude Desktop, claude code, src/client.ts)
   |  stdin: one JSON-RPC 2.0 object per line
   v
src/server.ts   main(): stdin -> LineSplitter -> dispatcher -> stdout
   |            stderr: logs only
   |
   +-- src/jsonrpc.ts    classify a decoded line as request / notification / response / invalid
   |                     error codes, response builders, line splitter
   +-- src/schema.ts     hand written JSON Schema subset used to validate tool arguments
   +-- src/tools.ts      search_jobs, get_job, job_stats, save_job, list_saved
   +-- src/resources.ts  jobs://all, jobs://{id}
   +-- src/prompts.ts    tailor-resume
   +-- src/jobs.ts       load data/jobs.json, search, stats, saved list in runs/saved.json
```

The dispatcher in `src/server.ts` is one function from an input line to an optional output line. The protocol methods it handles, in the order a session uses them:

| Method | Direction | What happens |
| --- | --- | --- |
| `initialize` | request | Client sends `protocolVersion`, `capabilities`, `clientInfo`. Server answers with its own version (`2025-06-18`), capabilities (`tools`, `resources`, `prompts`), `serverInfo`, and an `instructions` string the host may show the model. |
| `notifications/initialized` | notification | No `id`, so no response. The server logs it. |
| `ping` | request | Returns `{}`. Allowed before `initialize`. |
| `tools/list` | request | Returns each tool's `name`, `description`, and `inputSchema`. The schema object is the same one the server validates against. |
| `tools/call` | request | `{name, arguments}`. Arguments are validated first; failures are JSON-RPC `-32602` with the issues in `error.data`. The handler's result is `{content: [{type: "text", text}], structuredContent?, isError?}`. |
| `resources/list`, `resources/templates/list` | request | The 41 concrete URIs (`jobs://all` plus one per job) and the `jobs://{id}` template. |
| `resources/read` | request | `{uri}` in, `{contents: [{uri, mimeType, text}]}` out. Unknown URI is `-32002`. |
| `prompts/list`, `prompts/get` | request | `tailor-resume` takes `job_id` and optional `resume`; the server fills the job text into the returned user message. |
| anything else | request | `-32601` Method not found. |

Error shapes, which are the part people get wrong:

- A line that is not JSON: `{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error: ..."}}`.
- A JSON object that is not a valid request (wrong `jsonrpc`, `id: null`, non-string `method`): `-32600`, with the original `id` if one was usable.
- A request other than `ping` or `initialize` before the handshake: `-32600`.
- Unknown tool, wrong argument types, oversized query, unknown property: `-32602`. These are protocol errors because the caller broke the contract the schema published.
- A tool that ran and failed (job id does not exist, data file missing, handler threw): a normal result with `isError: true`. The model sees the failure text and can recover; the session is not disturbed.
- Unknown resource, including URIs like `jobs://../../etc/passwd`: `-32002`. Ids are matched against the in-memory list and never turned into file paths.

`src/client.ts` is a client of about 190 lines that spawns `node src/server.ts`, correlates responses by id, and exposes `sendRaw()` and `nextUnmatched()` so tests can push garbage and see what comes back. `scripts/demo.ts` uses its `onWire` hook to print every raw line.

## Results

Replay mode, 2026-09-11, Node v22.22.2. "Replay" here means a scripted, fixed sequence of requests against the real server over the shipped `data/jobs.json`. This server makes no model calls, so there is no live mode and no API key path to regenerate anything; `npm run measure` is the whole measurement.

Output of `node scripts/measure.ts`:

```
mode: replay (scripted session over data/jobs.json; this server makes no model calls, so there is no live mode)
date: 2026-09-11
node: v22.22.2

requests sent with an id: 34
responses received: 35 (34 matched by id, 1 with id null for the malformed line)
successful: 29
errors by code: -32601 x1, -32602 x3, -32002 x1

latency per method (ms, round trip through the child process)
method                            n    p50    p95
initialize                         1 131.21 131.21
jobs/teleport                      1   0.42   0.42
ping                               2   0.58   0.58
prompts/get                        1   0.34   0.34
prompts/get (missing arg)          1   0.21   0.21
prompts/list                       1   0.16   0.16
resources/list                     1   0.47   0.47
resources/read                     2   0.34   0.42
resources/read (traversal uri)     1   0.30   0.30
resources/templates/list           1   0.23   0.23
tools/call (bad args)              1   0.29   0.29
tools/call (unknown tool)          1   0.28   0.28
tools/call get_job                 5   0.33   0.42
tools/call job_stats               2   5.51   9.35
tools/call list_saved              1   0.36   0.36
tools/call save_job                2   0.78   0.92
tools/call search_jobs             8   0.66   1.00
tools/list                         2   0.51   0.52
all                               34   0.43   4.23

conformance checklist
  [pass] handshake: initialize returns protocolVersion 2025-06-18 and serverInfo
  [pass] ping returns an empty object
  [pass] every tool has an inputSchema of type object (5 tools)
  [pass] save_job then list_saved round trips through runs/measure-saved.json
  [pass] unknown method returns -32601
  [pass] unknown tool returns -32602
  [pass] wrong argument types return -32602 with issues in error.data
  [pass] path traversal looking resource URI returns -32002
  [pass] prompts/get with a missing required argument returns -32602
  [pass] tool level failure comes back as a result with isError: true, not a protocol error
  [pass] malformed JSON line returns -32700 with id null
  [pass] notifications (no id) get no response
  [pass] server still answers after every error case
  [pass] request before initialize returns -32600 (separate process)
  [pass] server exits 0 when stdin closes (exit code 0)
  [pass] stdout carried only JSON lines (35 lines, 0 non JSON)
  [pass] stderr carried the logs
  [pass] every error response had an integer code
  18/18 passed

wrote runs/measure.json
```

Notes on reading the table: the `initialize` latency includes spawning the Node process and loading the data file, which is why it is 130 ms while everything after it is under a millisecond. `job_stats` is the slowest real tool at 5 to 9 ms because it serializes a 3.5 KB result with pretty printing. Latencies are wall clock on one machine and will differ on yours.

Output of `node scripts/demo.ts`, abbreviated to the handshake, one tool call, and the two error shapes (the full run also lists tools, calls `job_stats`, reads a resource, and gets a prompt; long lines are cut at 700 bytes by the script):

```
# 1. Handshake: initialize request, then the initialized notification (no response expected)

[client -> server]
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"mcp-jobs-client","version":"0.1.0"}}}

[server -> client]
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":false},"resources":{"subscribe":false,"listChanged":false},"prompts":{"listChanged":false}},"serverInfo":{"name":"mcp-jobs-server","version":"0.1.0"},"instructions":"Jobs board for React Native and AI roles. Start with search_jobs (compact results), then get_job or the jobs://{id} resource for the full posting. job_stats gives counts and salary quartiles by tag. save_job and list_saved keep a short list across the session."}}

[client -> server]
{"jsonrpc":"2.0","method":"notifications/initialized"}

# 3. tools/call search_jobs

[client -> server]
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_jobs","arguments":{"tags":["react-native","mcp"],"limit":2}}}

[server -> client]
{"jsonrpc":"2.0","id":3,"result":{"content":[{"type":"text","text":"2 match(es), showing 2:\nj-031 | Developer Advocate, Mobile AI | Sunstone Relay | Remote, US (remote) | 150000-185000 USD | react-native,llm,devrel,mcp\nj-040 | React Native Engineer, MCP Client | Foxglove Terminal | Remote, US (remote) | 150000-185000 USD | react-native,mcp,agents,typescript"}],"structuredContent":{"total":2,"results":[{"id":"j-031","title":"Developer Advocate, Mobile AI","company":"Sunstone Relay","location":"Remote, US","remote":true,"salary":"150000-185000 USD","tags":["react-native","llm","devrel","mcp"]},{"id":"j-040","title":"React Native Engineer, MCP Client","company":"Foxglove Terminal","location": ... [812 bytes total, truncated for the demo]

# 7. Two error shapes: a protocol error (unknown tool) and a tool error (isError: true)

[client -> server]
{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"teleport_job","arguments":{"id":"j-001"}}}

[server -> client]
{"jsonrpc":"2.0","id":7,"error":{"code":-32602,"message":"Unknown tool: teleport_job","data":{"available":["search_jobs","get_job","job_stats","save_job","list_saved"]}}}

[client -> server]
{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"get_job","arguments":{"id":"j-999"}}}

[server -> client]
{"jsonrpc":"2.0","id":8,"result":{"content":[{"type":"text","text":"no job with id \"j-999\""}],"isError":true}}

# 8. Malformed line: the server answers with -32700 and id null, and keeps going

[client -> server]
{this is not json

[server -> client]
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error: line is not valid JSON"}}

# Server exited with code 0. Its stderr (never mixed into stdout):
  [mcp-jobs-server] info: loaded 40 jobs from /home/claude/portfolio/mcp-jobs-server/data/jobs.json
  [mcp-jobs-server] info: initialize from mcp-jobs-client 0.1.0
  [mcp-jobs-server] info: client sent notifications/initialized
  [mcp-jobs-server] warn: tools/call -> error -32602: Unknown tool: teleport_job
  [mcp-jobs-server] warn: parse error: Expected property name or '}' in JSON at position 1 (line 1 column 2)
  [mcp-jobs-server] info: stdin closed, exiting
```

`npm test` runs 44 tests in 13 suites (about 1.8 s), all offline, 12 of them over the real child process.

## Design decisions

**No SDK, on purpose.** The obvious choice is `@modelcontextprotocol/sdk`. It was rejected because the point of the repo is to show the protocol, and because the portfolio rule is zero runtime dependencies. The cost is about 300 lines (`jsonrpc.ts`, the dispatcher, the client) that the SDK would have provided, plus the risk of drifting from the spec as it evolves. The repo pins `2025-06-18` and implements only stdio; a production server should use the SDK.

**Protocol errors versus tool errors are different shapes.** A request that violates the published schema gets a JSON-RPC error (`-32602`), because the caller is wrong and retrying the same call will not help. A tool that ran and could not do the job returns `isError: true` inside a normal result, because the model should read the failure text and choose a different call. Collapsing these into one shape is the most common MCP server bug; it either hides tool failures from the model or turns every bad argument into a session-level fault.

**The validation schema is the advertised schema.** `src/schema.ts` implements a small subset of JSON Schema (types, required, bounds, enum, items, `additionalProperties: false`) and the same object is what `tools/list` returns. The alternative, validating by hand and writing a separate schema for the client, guarantees the two drift. The subset is small enough to read in five minutes, and everything a tool here needs fits in it.

**The server never crashes on bad input, and it starts without its data.** Every path through the dispatcher is wrapped: parse errors, invalid requests, thrown handlers, and a missing or malformed `data/jobs.json` all become messages, not exits. A missing data file is reported at startup on stderr and inside every tool result, so a host that connected to a misconfigured server sees the reason instead of a dead process. The test suite proves both cases over a real child process.

**Compact tool results plus `structuredContent`.** `search_jobs` returns one line per job in `content` (what the model reads) and the same rows as JSON in `structuredContent` (what a client program can use without parsing text). This doubles bytes on the wire for that call, which is cheap; it does not double model tokens, since hosts feed the model `content`. The full description is only sent by `get_job` and the `jobs://{id}` resource, so a search over 40 jobs costs a few hundred tokens rather than several thousand.

## When not to use this

- You are shipping an MCP server to users. Use the official SDK; it tracks the spec, handles Streamable HTTP, pagination, subscriptions, and cancellation, none of which are implemented here.
- Your data source is large. Everything here is an in-memory array read from one JSON file; there is no pagination on `resources/list`, so 40 postings is fine and 40,000 is not.
- You need remote transport or auth. This is stdio only, one client per process, and trusts whoever spawned it.
- You want multi-process safety on the saved list. `runs/saved.json` is read and rewritten on each call without locking, which is fine for one host and not for several.
- The client needs `listChanged` or resource subscriptions. Capabilities are advertised as `false` and the server never sends requests or notifications of its own.

## Running it

Requires Node 22.18 or newer. No install step is needed to run or test; `npm install` is only for `npm run typecheck`.

```
npm test            # 44 tests, offline, drives the real server as a child process
npm run measure     # scripted session, latency table, conformance checklist; writes runs/measure.json
npm run demo        # prints every raw JSON-RPC line of a short session
node src/server.ts  # run the server by hand; type a JSON-RPC line and press enter
```

Environment variables (all optional, see `.env.example`): `JOBS_DATA_PATH` to point at a different dataset, `JOBS_SAVED_PATH` to move the saved list, `MCP_JOBS_TRACE=1` to log every line to stderr, and `MCP_JOBS_FAULT_TOOL` as a test hook that makes one tool throw. No API keys are read anywhere.

### Connecting it to Claude Desktop / Claude Code

Claude Desktop: add the server to `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`, Windows: `%APPDATA%\Claude\claude_desktop_config.json`), using the absolute path to `src/server.ts` on your machine, then restart the app. The `command` must resolve to Node 22.18 or newer, since the server relies on native type stripping.

```json
{
  "mcpServers": {
    "jobs": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-jobs-server/src/server.ts"]
    }
  }
}
```

Claude Code: the same thing as one command. The `--` separates Claude Code's flags from the server command.

```
claude mcp add jobs -- node /absolute/path/to/mcp-jobs-server/src/server.ts
```

Then `claude mcp list` should show `jobs`, and inside a session `/mcp` shows its tools, resources, and the `tailor-resume` prompt. Try: "search the jobs server for remote react-native roles that mention mcp, then save the best one."

If the host reports the server as failed, run `MCP_JOBS_TRACE=1 node src/server.ts` by hand, paste `{"jsonrpc":"2.0","id":1,"method":"ping"}`, and check stderr. The most common problem is a `node` on PATH older than 22.18.

## Cost

The server itself makes no model calls, so running it costs nothing beyond a Node process. The cost shows up on the client side: every tool result and resource a host feeds to the model is input tokens. The figures below use the byte sizes of the content the model would see, measured with `Buffer.byteLength` over the same calls the demo makes (the whole wire line is larger because `structuredContent` repeats the data). Tokens are estimated at 4 bytes per token, a rough rule for English JSON; no tokenizer was run, so treat these as order of magnitude. List prices are from `src/pricing.ts`, USD per million tokens as of 2026-09; prices change.

| Message the model sees | Bytes (measured) | Tokens (estimated) |
| --- | --- | --- |
| `tools/list` (five schemas, sent once per session) | 2070 | 520 |
| `search_jobs` text content, 2 results | 291 | 75 |
| `search_jobs` text content, default limit of 10 | 1359 | 340 |
| `job_stats` text content | 1954 | 490 |
| `jobs://j-008` resource text | 677 | 170 |
| `tailor-resume` prompt text | 834 | 210 |
| Total for the demo session (tools/list, 2-result search, stats, resource, prompt) | 5826 | about 1460 |

At claude-sonnet-4-5 input pricing of 3.00 USD per million tokens: 1460 / 1,000,000 * 3.00 = 0.0044 USD per session, before the model's own output. At claude-haiku-4-5 (1.00): 0.0015 USD. At claude-opus-4-1 (15.00): 0.0219 USD. A `search_jobs` call at the default `limit: 10` is about 340 tokens because the tool returns one line per job; returning the full posting for the same ten jobs would be about 6770 bytes (ten times the resource above), around 1700 tokens, which is why `get_job` and the resource exist as a second step.