How to attach an MCP client¶
Goal¶
Connect an AI agent to Codefang over the Model Context Protocol (MCP) so the agent can run code analysis as a tool.
Prerequisites¶
codefanginstalled and on yourPATH.- An MCP-compatible client (for example, Claude Code or another agent that launches MCP servers over stdio).
- For the
codefang_historytool, an absolute path to a local Git repository.
Steps¶
- Confirm the MCP server starts. It communicates over stdio using JSON-RPC, the standard transport for local MCP tool use:
Press Ctrl-C to stop it — the agent will launch its own copy.
- Register Codefang as an MCP server in your client. For Claude Code, add it to
~/.claude/settings.json(user scope) or.claude/settings.json(project scope):
-
Restart the client so it picks up the new server. The agent then discovers three tools via the standard MCP
tools/listmethod:codefang_analyze(static analysis on inline code),uast_parse(parse source into a UAST), andcodefang_history(history analysis on a local repo). -
Ask the agent to run history analysis. The
codefang_historytool requires an absoluterepo_path; a relative path is rejected:
{
"name": "codefang_history",
"arguments": {
"repo_path": "/home/user/projects/myapp",
"analyzers": ["burndown", "devs"],
"limit": 500
}
}
- If a call misbehaves, reproduce it on the command line: the tool result equals what
codefang runprints for the same input (for examplecodefang run -a history/devs --format json --limit 500 /home/user/projects/myapp), and the server writes its own failures to stderr, which most clients show in their MCP log.
Result¶
The agent lists the three Codefang tools and returns structured analysis when it calls them. A successful codefang_analyze or codefang_history call that comes back without isError: true confirms the client is attached.