How code mode works
CP-MCP publishes exactly one MCP tool, code_mode. Claude passes it the body of
an async arrow function; the Worker runs that code in a sandboxed V8 isolate,
and the value the function returns becomes the MCP response.
Why one tool
Section titled “Why one tool”Cloudpath’s REST API spans three surfaces with hundreds of operations.
Registering each as its own MCP tool would overwhelm Claude’s tool list and
waste context on metadata the model rarely needs. Instead, the single
code_mode tool gives Claude three namespaced objects it drives from code:
core— Cloudpath Core API (admin)tenant— Tenant Portal APIproperty— Property Management API
Because the code runs in an isolate, Claude can plan, search, loop, and post-process across many calls without a tool-call round-trip per step. See The three API surfaces for what each object reaches.
The six primitives
Section titled “The six primitives”Each of the three objects exposes the same six primitives:
| Primitive | What it does |
|---|---|
list_tag_groups | High-level product areas within the surface |
list_tags | Endpoint categories within a group, with operation counts |
search_endpoints | Keyword search over the spec index, ranked by relevance |
list_endpoints_by_tag | Enumerate operations under a known tag |
get_endpoint_details | Full parameters, request body, and response schema for one operation |
call | Execute an authenticated call against an endpoint on that surface |
core carries two extra utilities on top of these six:
generate_passphrase and
generate_image.
The workflow
Section titled “The workflow”A typical code_mode program follows the same shape you would with the docs
open:
- Orient with
core.list_tag_groups()/core.list_tags()(or thetenant/propertyequivalents) when you don’t know where to look. - Discover with
search_endpoints({ query, tag?, method? })orlist_endpoints_by_tag({ tag }). - Inspect with
get_endpoint_details({ method, path })when you need the property table or examples. - Execute with
call({ method, path, pathParams?, query?, body? }). For thepropertysurface, also passpropertyMgmtPortalGuid.
Search results usually carry enough detail that Claude calls call directly
without a separate get_endpoint_details fetch.
Where the index comes from
Section titled “Where the index comes from”The endpoint index is extracted once from the Cloudpath REST API User Guide PDF
and bundled into the Worker, so search_endpoints and list_endpoints_by_tag
run in memory with no I/O. The richer full spec — per-endpoint property tables
and examples — is stored in object storage (Cloudflare R2) and lazy-loaded the
first time get_endpoint_details needs it in a given isolate.
Limits
Section titled “Limits”- The code you pass must be under 20,000 characters.
- Each
code_modeinvocation has a 20-second wall-clock budget; a program that exceeds it is aborted.
For the details of how call behaves — return shape, pagination, filtering,
and error handling — see Calling conventions.