MCP server and codemode
cemco-mcp is a remote MCP server built with the Cloudflare Agents SDK (createMcpHandler) and MCP SDK v2. It is
stateless per request, holds no data, and calls API and AUTH over Service Bindings.
- Endpoint:
https://mcp.cemco.app/mcp(streamable HTTP). GET /returns a short page about the server (JSON when asked withaccept: application/json);GET /healtha health check;GET /.well-known/oauth-protected-resourcethe OAuth resource metadata.
Authentication
Section titled “Authentication”Every request to /mcp is authenticated: the bearer token or API key is resolved by AUTH and mapped to an actor by
API. Without one, the server answers 401 with
WWW-Authenticate: Bearer resource_metadata="https://mcp.cemco.app/.well-known/oauth-protected-resource"which tells an MCP client such as Claude to run the OAuth 2.1 flow against auth.cemco.app (dynamic client
registration, then the user signs in and consents). Customer logins are refused: the portal is the only customer
surface. The OAuth flow needs AUTH_URL and MCP_URL set on cemco-auth (they are set for production); without
them the authorization server answers not connected and only API keys work.
About fifty core operations are listed as their own tools (TOOL_OPERATIONS in workers/mcp/src/catalog.ts): the
everyday reads and writes on accounts, contacts, orders, machines, service, parts, tasks and the agenda. The tool name
is the operation name with the dot replaced by an underscore (orders.advance → orders_advance); the description and
input schema are the operation’s own (no output schemas, to keep tools/list small). Every other staff operation is
reached through search and execute below, so nothing is lost, and tools/list stays under 100 KB for every role.
Customer and system operations are not exposed. The actor’s role still applies: a viewer sees the read tools. Each
tool carries MCP hints (readOnlyHint, destructiveHint) so clients can ask before a change. An operation whose
handler has not been written yet answers with an error (HTTP 501, details.notImplemented); the implemented flag in
GET https://api.cemco.app/v1/ops shows which ones.
OAuth access tokens issued by auth.cemco.app are for this MCP server only. The REST API (api.cemco.app) and the
agents worker refuse them with 401; use a session or an API key there.
The server also offers four prompts (daily_briefing, file_email, account_review, log_service_visit) and
resources describing the business rules.
See the API reference for every tool’s input and output.
Codemode
Section titled “Codemode”Besides the per-operation tools, two tools let a model work with the whole catalog in code:
search: find operations by what they do; returns names, descriptions and TypeScript signatures. Theexecutedescription lists every operation the actor may call by name only, so a model callssearchfor the signature first.execute: run a short TypeScript program against a typedcrmobject (await crm.orders.list({ stage: "received" })). The program runs in an isolated Worker created with the Worker Loader (LOADERbinding), with no network access; its only way out is thecrmobject, which calls the API as the signed-in actor.
Codemode suits multi-step questions (“for every machine out of warranty in Texas, list its last ticket”) in one round trip.
In-chat views (MCP Apps)
Section titled “In-chat views (MCP Apps)”Seven operations declare a view and return it with their result, so Claude renders a compact version of the app screen in the chat:
| Operation | View |
|---|---|
reports.dashboard |
ui://cemco/dashboard.html |
accounts.get |
ui://cemco/account.html |
orders.get |
ui://cemco/order.html |
machines.list |
ui://cemco/installed-base.html |
tickets.board |
ui://cemco/service-board.html |
parts_orders.get |
ui://cemco/parts-order.html |
agenda.get |
ui://cemco/agenda.html |
The views are built in packages/views (Lit) to single self-contained HTML files and served as MCP resources. They
call the same tools for follow-up actions.
Try it locally
Section titled “Try it locally”bun run --filter @cemco/mcp dev # http://localhost:8790/mcpnpx @modelcontextprotocol/inspector # connect to http://localhost:8790/mcp with header x-cemco-dev-user