Agents

Hosting the MCP server

Culm's MCP server is supported over a product's own transport and sign-in, by this recipe only. culm mcp itself listens on standard input and output and on 127.0.0.1⁠, and nothing else in Culm serves beyond the machine. The test that holds this page up is

packages/tools/__tests__/mcp/hosted.spec.ts

; it imports from @culmjs/tools by name and uses no listenLocal⁠.

A product that keeps its site as a folder

folderMcpOptions builds from a site folder what culm mcp serves: the store, the registry, the guards and the package redaction. It is remote unless you say otherwise. This sample is the test's server, with the product's sign-in a bearer token:

// `dir` is the site folder, `port` the product's own port, and `signedIn` the product's own check.
import { createServer } from 'node:http'
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
import { createMcpServer, folderMcpOptions, openProject } from '@culmjs/tools'

const options = {
  ...(await folderMcpOptions(dir, await openProject(dir))),
  jsonOps: false, // the full interface, with `read`, `apply` and `restore`, as the test serves it (`true` is the compact profile `culm mcp` has, which has no `read`)
}

createServer(async (req, res) => {
  if (!signedIn(req)) return void res.writeHead(401).end('Sign in') // the product's own check
  const server = createMcpServer(options)
  const transport = new StreamableHTTPServerTransport({
    sessionIdGenerator: undefined,
    enableJsonResponse: true,
  })
  res.on('close', () => void transport.close().then(() => server.close()))
  await server.connect(transport)
  await transport.handleRequest(req, res)
}).listen(port)

The sign-in comes first: a request that is not signed in never reaches a server, and nothing is applied (the test checks a 401 and an unchanged revision). The sample builds a server for each request; the options are built once.

What the flag means

Do not pass { local: true }⁠. Without it every caller is an agent, and the mayTurnToolsOn setting in culm.json is never read, so it is off for every remote caller (owner ruling 21). culm mcp is the one caller that passes it. Turning tools on is a person's change: they make it locally with culm agents on⁠, or through the product's own interface (see below).

A remote caller is refused each person-only change, each with its rule: backends⁠, grants⁠, secret⁠, protected⁠, textRange⁠, agents and package (the rules). The test applies one op for each, including turning tools on and restore to a revision that has them on, and checks that nothing was applied.

What a remote caller does not read

A package's own pieces are shown to a remote caller as a reference: the piece's name and settings, not its nodes. find does not look inside a piece at all, so it finds none of its words. read with what: 'page' and tree: { component: <id> } returns the reference, and that is where the redaction shows. A remote find therefore shows a use of a piece as an instance and nothing of its text, and read shows the reference with none of the piece's own text. The test asserts both.

A product with its own store and no packages

Build the server over your store and pass the two guards:

import { createMcpServer, protect, toolsOnGuard } from '@culmjs/tools'

const server = createMcpServer({
  store,
  registry,
  site: 'main',
  jsonOps: true,
  allow: (op, doc, head) =>
    protect(op, doc, head) ?? toolsOnGuard(op, doc, head),
})

This never reads mayTurnToolsOn⁠, so it is the remote setting. Leaving allow out removes the protection: a caller could then change backends, grants, secrets and the rest, turn tools on, and widen the text range. Nothing else in createMcpServer supplies it.

A product with its own store and packages

Outside this recipe. The guard that keeps a package's pieces as approved and the redaction that hides their text are not exported, and they need the folder's file map, which folderMcpOptions reads from a folder. Keep the site as a folder.

A person's change in a hosted product

A person's change is made by the product's own interface calling core directly, not through this server. The product owns the proof that a person made it. Culm records that a revision came from Culm or from a hand edit, not from whom.

Not in Culm

  • Identity, accounts, and audit of who called.

  • A transport: the product brings its own, and its own sign-in.

  • A remote caller can still reach add_package (it copies a package in but cannot approve it), network fetch of fonts, icons and images, build⁠, measure and render⁠. Whether remote mode should turn these off is open (stage-10b-exit.md).

Edit this page on GitHub