MCP Server
codeknife mcp starts a Model Context Protocol server on standard input and output. Use it when your coding agent speaks MCP and you want it to call CodeKnife tools (check, fix, dossier, reuse, blast, test, verify) directly instead of shelling out and parsing text.
Try it
Section titled “Try it”The server reads one JSON-RPC message per line and writes one response per line. You can drive it by hand with printf:
printf '%s\n' \ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"demo","version":"0"}}}' \ '{"jsonrpc":"2.0","method":"notifications/initialized"}' \ '{"jsonrpc":"2.0","id":2,"method":"ping"}' \ | codeknife --no-cache mcp{"id":1,"jsonrpc":"2.0","result":{"capabilities":{"tools":{"listChanged":false}},"protocolVersion":"2025-06-18","serverInfo":{"name":"codeknife","version":"0.2.0"}}}{"id":2,"jsonrpc":"2.0","result":{}}The notification on line two produces no output. When standard input closes, the server exits with code 0.
A tool call returns the tool’s JSON report as text inside content:
printf '%s\n' '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"codeknife_reuse","arguments":{"query":"messy flag"}}}' \ | codeknife --no-cache mcp{"id":3,"jsonrpc":"2.0","result":{"content":[{"text":"{\n \"query\": \"messy flag\",\n \"scanned_items\": 2,\n \"candidates\": [\n {\n \"symbol\": \"sloppy_demo::messy\",\n \"name\": \"messy\",\n \"kind\": \"fn\",\n \"visibility\": \"public\",\n \"file\": \"src/main.rs\",\n \"start_line\": 4,\n \"end_line\": 20,\n \"language\": \"rust\",\n \"score\": 44.15199,\n \"signature\": \"pub fn messy(a: bool, b: bool, p1: i32, p2: i32, p3: i32, p4: i32) -> i32\",\n \"doc_summary\": \"SPDX-License-Identifier: MIT ========= SECTION ========= Step 1: Added as requested\",\n \"matched_terms\": [\n \"messy\"\n ],\n \"inbound_callers\": 0,\n \"reuse_hint\": \"use sloppy_demo::messy;\"\n }\n ]\n}","type":"text"}],"isError":false}}The text field is the pretty-printed JSON report. There is always exactly one content item, of type text.
The full list of tools, their input schemas and result shapes is on MCP Tools.
Transport
Section titled “Transport”| Property | Value |
|---|---|
| Transport | stdio only. There is no network listener. |
| Framing | One JSON value per line, newline-terminated. No Content-Length headers. |
| Blank lines | Lines that are empty after trimming whitespace are skipped. |
| Output | Each response is a single line of compact JSON, flushed immediately. |
| Ordering | Requests are handled one at a time, in order. A slow tool call blocks the next request. |
| Shutdown | The server returns when standard input reaches end of file. Exit code 0. |
| Encoding | Input must be UTF-8. A non-UTF-8 line stops the server with codeknife error: stream did not contain valid UTF-8 on stderr and exit code 2. |
The server never prints anything but JSON-RPC responses on stdout.
Protocol version and server info
Section titled “Protocol version and server info”initialize echoes the protocolVersion string the client sends. If the client sends none, the server answers with 2024-11-05.
The initialize result is always:
| Field | Value |
|---|---|
protocolVersion |
The client’s params.protocolVersion, or 2024-11-05 |
capabilities |
{"tools":{"listChanged":false}} |
serverInfo.name |
codeknife |
serverInfo.version |
The binary’s package version, for example 0.2.0 |
The server advertises only the tools capability. It offers no resources, prompts, logging or sampling.
printf '%s\n' '{"jsonrpc":"2.0","id":3,"method":"initialize","params":{}}' | codeknife --no-cache mcp{"id":3,"jsonrpc":"2.0","result":{"capabilities":{"tools":{"listChanged":false}},"protocolVersion":"2024-11-05","serverInfo":{"name":"codeknife","version":"0.2.0"}}}Methods
Section titled “Methods”| Method | Behaviour |
|---|---|
initialize |
Returns protocol version, capabilities and server info (above). The server does not require initialize before other calls. |
ping |
Returns an empty object, {}. |
tools/list |
Returns {"tools":[...]} with all seven tool definitions. |
tools/call |
Runs the tool named in params.name with params.arguments (an empty object if omitted). |
Any message without an id |
Treated as a notification. No response, whatever the method, including notifications/initialized. |
Any other method with an id |
Error -32601. This covers resources/list, prompts/list and the rest. |
The server does not check the jsonrpc field. A message with an id but no method is answered as an unknown method with an empty name.
Errors
Section titled “Errors”There are two kinds of failure. Protocol errors come back as a JSON-RPC error object. Tool failures come back as a normal result with isError: true.
| Situation | Response |
|---|---|
| Line is not valid JSON | error.code -32700, message parse error: ..., id is null |
| Unknown method | error.code -32601, message method not found: <method> |
tools/call without a string params.name |
error.code -32602, message missing `params.name` in tools/call |
| Unknown tool name | result.isError true, text error: unknown MCP tool `<name>` |
| Missing required argument | result.isError true, for example error: missing required string parameter `query` |
| Any error inside the tool run | result.isError true, text error: followed by the error chain |
Real responses from one session:
{"error":{"code":-32601,"message":"method not found: resources/list"},"id":4,"jsonrpc":"2.0"}{"error":{"code":-32602,"message":"missing `params.name` in tools/call"},"id":5,"jsonrpc":"2.0"}{"id":6,"jsonrpc":"2.0","result":{"content":[{"text":"error: unknown MCP tool `nope`","type":"text"}],"isError":true}}{"id":7,"jsonrpc":"2.0","result":{"content":[{"text":"error: missing required string parameter `query`","type":"text"}],"isError":true}}{"error":{"code":-32700,"message":"parse error: expected ident at line 1 column 2"},"id":null,"jsonrpc":"2.0"}{"id":8,"jsonrpc":"2.0","result":{"content":[{"text":"error: unsupported language `cobol` (use rust, ts, js, python, go)","type":"text"}],"isError":true}}A tool result with isError: false does not mean the code passed. For example, codeknife_check on a repository with warnings returns isError: false and a report with "passed": false. Read the report, not the flag.
Global flags and the server
Section titled “Global flags and the server”Global flags given on the codeknife mcp command line set defaults for every tool call. Not all of them apply.
| Global flag | Effect on the server |
|---|---|
--path <dir> |
Sets the default repository root. Each tool’s path argument overrides it. |
--no-cache |
Default for each tool’s no_cache argument. |
--strict |
Default for each tool’s strict argument. |
--changed |
Ignored. Each call uses its own changed argument, default false. |
--since |
Ignored. Each call uses its own since argument. |
--format |
Ignored. Tool results are always JSON. |
--max-items |
Ignored. |
A relative path argument is resolved against the server’s root (the --path value, or the working directory), then canonicalized if it exists. With the server started as codeknife --no-cache --path sloppy mcp, a call with "path":"../clean" analyzes the sibling clean directory.
Register it with an MCP client
Section titled “Register it with an MCP client”codeknife init does not write any MCP client configuration. Configure your client to launch this command over stdio:
codeknife mcpTo pin the repository and keep the server from writing .codeknife/ cache files, add global flags before mcp:
codeknife --path /path/to/repo --no-cache mcpWithout --path, the server uses its working directory, so start it from the repository root. See The .codeknife Directory for what the cache holds.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Standard input closed normally. Tool failures do not change this. |
2 |
An I/O error on stdin or stdout, including non-UTF-8 input. |
Also available via
Section titled “Also available via”Each tool maps to a CLI command: codeknife_check to codeknife check, codeknife_fix to codeknife fix, codeknife_dossier to codeknife dossier, codeknife_reuse to codeknife reuse, codeknife_blast to codeknife blast, codeknife_test to codeknife test, codeknife_verify to codeknife verify. The differences between each tool and its command are listed on MCP Tools.