Skip to Content
LoremLLM

@loremllm/mcp

A fake MCP server built on the official SDK. Run it over stdio, HTTP or in memory.

npm install -D @loremllm/mcp @modelcontextprotocol/sdk

createMockMcpServer returns an McpServer from @modelcontextprotocol/sdk, already populated from scenarios. Every transport the SDK ships works with it, and you can still call registerTool for anything a scenario can't express.

mock-mcp.ts
import { createMockMcpServer, json, toolError } from "@loremllm/mcp";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = createMockMcpServer({
  name: "orders",
  version: "1.0.0",
  tools: {
    lookupOrder: {
      description: "Find an order by id",
      inputSchema: { id: z.string() },
      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",
      mimeType: "text/markdown",
      text: "Refunds within 30 days.",
    },
  ],
});

await server.connect(new StdioServerTransport());

inputSchema takes a Zod raw shape, as registerTool does, or a JSON Schema object.

Transports

TransportUse it for
StdioServerTransportClients that spawn a command
StreamableHTTPServerTransportHTTP clients, mounted in your own server
InMemoryTransport.createLinkedPair()Tests: connect a Client in the same process

server.listen({ port }) is a shortcut that serves Streamable HTTP at http://localhost:<port>/mcp.

In a test

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";

const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await server.connect(serverTransport);

const client = new Client({ name: "test", version: "1.0.0" });
await client.connect(clientTransport);

const result = await client.callTool({ name: "lookupOrder", arguments: { id: "A-1042" } });
// result.structuredContent → { status: "delivered", total: 48 }

Recorded calls

server.calls;
// [{ name: "lookupOrder", arguments: { id: "A-1042" }, result: { structuredContent: { ... } } }]

The same definition can be pushed to the hosted API as a mock's mcp block. See the MCP endpoint.

On this page