Skip to content

chant serve mcp

chant serve mcp [path]

chant serve mcp starts an MCP (Model Context Protocol) server over stdio. This allows AI agents that support MCP — such as Claude Code, Cursor, and Windsurf — to interact with your chant project programmatically.

Typically you don’t run this directly. chant init detects your IDE and writes the MCP config to the appropriate global config file — ~/.claude/mcp.json for Claude Code, ~/.cursor/mcp.json for Cursor, or ~/.config/mcp/mcp.json otherwise. Your agent picks it up automatically. See Agent Integration.

The server exposes six core tools that agents can invoke:

Build chant infrastructure code and generate output for the target lexicon.

ParameterTypeRequiredDescription
pathstringYesPath to the infrastructure directory or file
outputstringNoOutput file path (returns in response if omitted)
format"json" | "yaml"NoOutput format (default: json)

Returns { success, resourceCount, output, format }.

Lint chant infrastructure code and report issues.

ParameterTypeRequiredDescription
pathstringYesPath to the infrastructure directory or file
fixbooleanNoAuto-fix fixable issues (default: false)

Returns { success, errorCount, warningCount, diagnostics, output }.

Import external templates and convert them to chant TypeScript.

ParameterTypeRequiredDescription
sourcestringYesPath to the template file to import
outputstringNoOutput directory (default: ./infra/)

Returns { success, lexicon, generatedFiles, warnings }.

Summarize the resources in a chant project.

ParameterTypeRequiredDescription
pathstringYesPath to the infrastructure directory
format"markdown" | "json"NoOutput format (default: markdown)

Returns a structured summary of resource counts, entity types, and lexicon groupings.

Generate starter files for a chant project.

ParameterTypeRequiredDescription
patternstringYesResource pattern to scaffold (e.g. "s3-bucket", "pipeline")
lexiconstringNoLexicon to use for templates

Returns { success, files } with generated file contents.

Search available resource types across loaded lexicons.

ParameterTypeRequiredDescription
querystringYesSearch query (case-insensitive substring match)
lexiconstringNoFilter to a specific lexicon
limitnumberNoMaximum results (default: 20)

Returns matching resource type entries sorted by relevance.

Every Op tool takes an optional runtime, the same choice chant run --on makes on the command line. Omitted, it is the built-in local runtime, which executes the Op in this process.

List every Op discovered from *.op.ts files with the run state the runtime reports.

ParameterTypeRequiredDescription
runtimestringNoRuntime to address: a lexicon name with an opRuntime, or local (the default)

Run an Op on a runtime and return its result.

ParameterTypeRequiredDescription
namestringYesOp name (must match an *.op.ts file)
runtimestringNoRuntime to address: a lexicon name with an opRuntime, or local (the default)

Show the state the runtime reports for an Op’s latest run.

ParameterTypeRequiredDescription
namestringYesOp name
runtimestringNoRuntime to address: a lexicon name with an opRuntime, or local (the default)

Returns { op, runId, state, startedAt, endedAt, records, gate }. records is the per-phase StepRecord[] array (present when the Op’s *.op.ts is discoverable; see Progress and gate state) — the same shape --progress-json streams. gate is the pending gate ({ name, since }), absent when none is standing.

Record a gate’s resolution on the gate ledger, then wake the runtime hosting the gated run. This is the rename of op-signal, and a different act: a gate is resolved by recording the fact, not by sending a message to a waiting workflow.

ParameterTypeRequiredDescription
namestringYesOp name
gatestringYesGate name (must match the gate’s name in the Op)
approverstringNoWho approved; defaults to the CI or shell identity
notestringNoFree-text context recorded on the resolution
urlstringNoAbsolute http/https URL this resolution happened at
runtimestringNoRuntime to address: a lexicon name with an opRuntime, or local (the default)

Return a markdown report for an Op’s latest run.

ParameterTypeRequiredDescription
namestringYesOp name
runtimestringNoRuntime to address: a lexicon name with an opRuntime, or local (the default)

Lexicon plugins can contribute additional tools. Plugin tools are namespaced as {pluginName}:{toolName} to avoid conflicts with core tools.

The server provides resources that agents can read for context:

URIMIME TypeDescription
chant://contexttext/markdownLexicon-specific instructions, patterns, and best practices
chant://examples/listapplication/jsonJSON array of available examples ([{ name, description }])
chant://examples/<name>text/typescriptSource code of a specific example
chant://opsapplication/jsonList of all discovered Ops with metadata
chant://ops/{name}/runsapplication/jsonRecent run history for a specific Op
chant://ops/{name}/runs/latestapplication/jsonLatest run state for a specific Op

Lexicon plugins can contribute additional resources, namespaced as chant://{pluginName}/{path}. Plugin resources with /examples/ in their URI are automatically included in the examples list.

chant init detects your IDE and adds the MCP server to the appropriate global config file:

IDEConfig path
Claude Code~/.claude/mcp.json
Cursor~/.cursor/mcp.json
Other~/.config/mcp/mcp.json

The config looks like:

{
"mcpServers": {
"chant": {
"command": "npx",
"args": ["chant", "serve", "mcp"]
}
}
}

If your agent doesn’t auto-detect the MCP config, configure the server manually. The command is:

Terminal window
chant serve mcp

The server communicates over stdin/stdout using JSON-RPC 2.0 with line-based framing (one JSON object per line).

The MCP server implements the Model Context Protocol specification version 2024-11-05.

MethodDescription
initializeHandshake — returns protocol version, capabilities, and server info
tools/listList all available tools (core + plugin-contributed)
tools/callInvoke a tool by name with parameters
resources/listList all available resources (core + plugin-contributed)
resources/readRead a resource by URI
CodeMeaning
0Clean shutdown
1Unknown subcommand or startup failure