Turns a Tupik app into an MCP server (Streamable HTTP, JSON-RPC 2.0, stateless). The routes you opt in become
tools whose input schema comes from the route contract. A tool call is a request to app.fetch, so the same access
rules, principal, validation and response shaping apply; classified pii/health fields are removed before the
result reaches the model unless you release them.
npm install @tupik/mcp @tupik/coreimport { createApp, createModule } from '@tupik/core';
import { createMcpServer } from '@tupik/mcp';
const patients = createModule('/patients').get('/:id', {
access: { owner: (ctx) => findPatient(ctx.params.id)?.doctorId },
tags: ['mcp'], // opt-in: only tagged routes become tools
schema: { response: { 200: Patient } }, // Patient classifies email as pii, diagnosis as health
handler: (ctx) => findPatient(ctx.params.id),
});
const app = createApp({ authenticate: bearerUser }).register(patients);
const mcp = createMcpServer(app, { name: 'clinic', version: '1.0.0' });
// Workers: export default { fetch: (request) => new URL(request.url).pathname === '/mcp' ? mcp.fetch(request) : app.fetch(request) };tools/call { name: 'getPatientsById', arguments: { params: { id: 'p1' } } } runs GET /patients/p1 with the
authorization and cookie headers of the MCP request. No principal gets UNAUTHORIZED, someone else's patient
gets NOT_FOUND, and the doctor gets the record without email and diagnosis (listed in _meta['tupik/removed']).
| Option | Default | Purpose |
|---|---|---|
tools |
{ tag: 'mcp' } |
Routes tagged with tag, or a list of 'METHOD /path' (unknown entries throw) |
allowDataClasses |
[] |
Classes the model may receive ('pii', 'health'); secret is always removed |
forwardHeaders |
['authorization', 'cookie'] |
Headers copied to the app call |
allowedOrigins |
[] |
Origin values accepted (DNS rebinding guard); requests without Origin pass |
name, version, instructions |
tupik, 0.0.0 |
Sent on initialize |
schemaConverter |
none | Standard Schema to JSON Schema for the tool input schemas |
Protocol: initialize (versions 2025-06-18, 2025-03-26), ping, tools/list, tools/call; notifications get
202; batches, GET streams and sessions are not offered (405 / error). No SDK dependency: it runs wherever fetch does.
MIT