Skip to content

MCP server

@contextlint/mcp-server exposes contextlint’s features to AI hosts via the Model Context Protocol. Once registered with an MCP-capable host (Claude Desktop, Cursor, Cline, Codex, etc.), AI can run lint, query the graph, and analyze impact mid-conversation.

Terminal window
npm install -D @contextlint/mcp-server

npx @contextlint/mcp-server also works, so pick the install style — global or per-project — that matches the host’s configuration conventions.

The MCP server is a simple stdio command. Each host’s configuration file takes the same kind of entry.

Edit claude_desktop_config.json (on macOS: ~/Library/Application Support/Claude/claude_desktop_config.json).

{
"mcpServers": {
"contextlint": {
"command": "npx",
"args": ["@contextlint/mcp-server"]
}
}
}

Add the same shape of entry to .cursor/mcp.json (project-specific) or ~/.cursor/mcp.json (user-wide).

{
"mcpServers": {
"contextlint": {
"command": "npx",
"args": ["@contextlint/mcp-server"]
}
}
}

MCP-capable hosts like Cline, Codex, and Windsurf use roughly the same configuration format. Match command and args as above and they should work.

The MCP server exposes the following tools. AI calls them as needed during conversation.

ToolPurpose
lintValidate Markdown content directly with explicit rules
lint-filesValidate multiple files via glob patterns and a config file
context-graphBuild and return the document dependency graph
context-sliceExtract the minimal set of files related to a query (ID / keyword / file path)
impact-analysisClassify files affected directly or transitively by changes to a file

Validates Markdown content passed inline against an explicit rule set. Useful for ad-hoc validation that doesn’t need a config file.

InputTypeDescription
contentstringThe Markdown to validate
rulesobject[]Rules to apply (rule plus optional options)

Validates files matching glob patterns using the configuration in contextlint.config.json. Equivalent to running npx contextlint, but invokable through MCP.

InputTypeDescription
patternsstring[] (optional)Glob patterns. Falls back to the config’s include, then to ["**/*.md"]
configPathstring (optional)Path to a config file. Auto-detected from parent directories if omitted
cwdstring (optional)Working directory

Builds the document dependency graph and returns it. With format: "json", the output is structured JSON; otherwise it’s a human-readable summary. Useful for “give the AI an overview of the repository” use cases.

Pass an ID (e.g. REQ-101), keyword, or file path as query, and the tool returns the minimal set of related files. depth controls traversal depth (default 2). Lets you stay token-efficient while feeding precise context to AI.

Classifies the documents affected by a change to a file into direct (directly referencing it) and transitive (reachable through a chain of references). Use it before refactors or deletions to confirm safety.

lint-files, context-graph, context-slice, and impact-analysis all consult contextlint.config.json. If no config is found, they error out — set things up first with the contextlint-init Skill or Quick Start — Manual.

The MCP server and the CLI share the same lintFiles pipeline from @contextlint/core. Their output formats are aligned, so what AI sees through MCP matches what humans see in the CLI.