# MCP

Serve fake MCP tools, resources and prompts from a mock.

Every mock is also an MCP server, over Streamable HTTP:

```
https://api.loremllm.com/m/<mock>/mcp
```

Add it to any MCP client:

```json title="mcp.json"
{
  "mcpServers": {
    "support": { "url": "https://api.loremllm.com/m/support-bot/mcp" }
  }
}
```

## Defining the server [#defining-the-server]

Field names follow the [MCP spec](https://modelcontextprotocol.io/specification), so a definition reads like a `tools/list` or `resources/list` result.

```ts
import { defineMock, json, text, toolError } from "loremllm";

defineMock("support-bot", {
  mcp: {
    tools: {
      lookupOrder: {
        description: "Find an order by id",
        inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
        scenarios: [
          { when: { input: { id: "A-1042" } }, reply: json({ status: "delivered", total: 48 }) },
          { reply: toolError("Order not found") },
        ],
      },
    },
    resources: [
      {
        uri: "docs://refund-policy",
        name: "refund-policy",
        title: "Refund policy",
        mimeType: "text/markdown",
        text: "Refunds within 30 days.",
      },
    ],
    prompts: [
      {
        name: "triage",
        description: "Triage a ticket",
        arguments: [{ name: "ticket", required: true }],
        messages: ({ ticket }) => [
          { role: "user", content: { type: "text", text: `Triage: ${ticket}` } },
        ],
      },
    ],
  },
});
```

Tool `scenarios` work like mock scenarios, but `when.input` matches the call's `arguments` (partial deep equality, RegExps allowed in leaves). `inputSchema` also accepts a Zod schema in config files.

## Tool results [#tool-results]

| Builder             | `tools/call` result                                               |
| ------------------- | ----------------------------------------------------------------- |
| `text("...")`       | `content: [{ type: "text", text }]`                               |
| `json(value)`       | `structuredContent: value`, plus the same JSON as a `text` block  |
| `image(data, mime)` | `content: [{ type: "image", data, mimeType }]`                    |
| `resourceLink(uri)` | `content: [{ type: "resource_link", uri, name }]`                 |
| `toolError("...")`  | `isError: true` with the message as a `text` block                |
| `error(-32602)`     | A JSON-RPC error instead of a result, for protocol-level failures |

`toolError` is the one to reach for: per the spec, tool failures are results the model can read, not protocol errors.

## What it supports [#what-it-supports]

- `initialize`, with `tools`, `resources` and `prompts` capabilities
- `tools/list` and `tools/call`, including `outputSchema` and `structuredContent`
- `resources/list`, `resources/read`, `resources/templates/list` and `resources/subscribe`
- `prompts/list` and `prompts/get`
- `notifications/progress` when the client sends a `progressToken`, timed by `delay(ms)`
- `notifications/tools/list_changed` when you push a new version
- Streamable HTTP: one endpoint for `POST` and `GET`, sessions via the `Mcp-Session-Id` header

## Testing an MCP client [#testing-an-mcp-client]

Point your agent's MCP client at the mock, and its model at the same mock's OpenAI or Anthropic endpoint. You control both the tool list your agent sees and what each tool returns.

For a local or stdio server, use [@loremllm/mcp](/docs/packages/mcp).