An intelligent Model Context Protocol (MCP) server that provides AI agents with powerful code comparison and analysis capabilities.
The Smart Diff MCP Server exposes the advanced code comparison engine through the Model Context Protocol, allowing AI agents to:
- Compare code across files, directories, or commits
- List functions sorted by change magnitude
- Query detailed diffs for individual functions
- Access comparison results through structured resources
The server provides four main tools:
Initiates a comparison between two code locations (files or directories).
Parameters:
source_path(required): Path to source code locationtarget_path(required): Path to target code locationrecursive(optional, default: true): Whether to scan directories recursivelyfile_patterns(optional): File patterns to include (e.g.,["*.rs", "*.py"])ignore_patterns(optional): File patterns to ignore
Returns: A comparison ID for querying results
Example:
{
"name": "compare_locations",
"arguments": {
"source_path": "/path/to/old/code",
"target_path": "/path/to/new/code",
"recursive": true
}
}Lists all changed functions from a comparison, sorted by change magnitude (most changed first).
Parameters:
comparison_id(required): The comparison ID fromcompare_locationslimit(optional, default: 100): Maximum number of functions to returnchange_types(optional): Filter by change types (["added", "deleted", "modified", "renamed", "moved"])min_magnitude(optional): Minimum change magnitude (0.0 to 1.0)
Example:
{
"name": "list_changed_functions",
"arguments": {
"comparison_id": "550e8400-e29b-41d4-a716-446655440000",
"limit": 50,
"change_types": ["modified", "added"],
"min_magnitude": 0.3
}
}Gets detailed diff information for a specific function.
Parameters:
comparison_id(required): The comparison IDfunction_name(required): Name of the functioninclude_content(optional, default: true): Whether to include full source/target content
Example:
{
"name": "get_function_diff",
"arguments": {
"comparison_id": "550e8400-e29b-41d4-a716-446655440000",
"function_name": "process_data"
}
}Gets summary statistics for a comparison.
Parameters:
comparison_id(required): The comparison ID
Example:
{
"name": "get_comparison_summary",
"arguments": {
"comparison_id": "550e8400-e29b-41d4-a716-446655440000"
}
}The server exposes comparison results as MCP resources with the following URI scheme:
codediff://comparison/{id}/summary- Comparison summary statistics (JSON)codediff://comparison/{id}/functions- List of all changed functions (JSON)codediff://comparison/{id}/function/{name}- Detailed diff for a specific function (JSON)
Build the MCP server:
cargo build --release -p smart-diff-mcp-serverThe binaries will be available at:
target/release/smart-diff-mcpfor stdio MCPtarget/release/smart-diff-mcp-httpfor HTTP MCP and legacy SSE
The MCP server communicates via stdio (standard input/output) as per the MCP specification:
./target/release/smart-diff-mcpThe server reads JSON-RPC messages from stdin and writes responses to stdout.
For HTTP clients such as Codex streamable HTTP, run:
./target/release/smart-diff-mcp-httpBy default this listens on 127.0.0.1:8011 and exposes:
POST /mcpfor streamable HTTP MCPGET/POST /ssefor legacy SSE compatibilityPOST /messagefor legacy SSE message deliveryGET /healthfor health checks
You can override the bind address with:
SMART_DIFF_MCP_HOST=127.0.0.1 SMART_DIFF_MCP_PORT=8011 ./target/release/smart-diff-mcp-httpAdd to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"smart-diff": {
"command": "/absolute/path/to/codediff/target/release/smart-diff-mcp",
"args": [],
"env": {
"RUST_LOG": "info"
}
}
}
}Important: Use the absolute path to the binary.
Add to ~/.codex/config.toml:
[mcp_servers.smart-diff]
url = "http://127.0.0.1:8011/mcp"If you already have Codex configured to use http://127.0.0.1:8011/sse, the HTTP server also accepts JSON-RPC POST requests on that path for compatibility, but /mcp is the preferred endpoint.
Any MCP-compatible client can use the server by launching it as a subprocess and communicating via stdio using JSON-RPC 2.0 messages.
-
Start a comparison:
Agent: Use compare_locations to compare /old/src with /new/src -
List changed functions:
Agent: Use list_changed_functions with the comparison_id to see what changed -
Examine specific changes:
Agent: Use get_function_diff to see details for the most changed function
The MCP server is built on top of the Smart Diff engine and provides:
- Comparison Manager: Manages multiple concurrent comparisons
- Tool Handler: Implements MCP tools for code analysis
- Resource Handler: Exposes comparison results as MCP resources
- Stdio Transport: JSON-RPC communication over stdin/stdout
- HTTP Transport: Streamable HTTP MCP at
/mcpwith compatibility routing for legacy SSE clients
The server supports the same languages as the Smart Diff engine:
- Rust (
.rs) - Python (
.py) - JavaScript/TypeScript (
.js,.ts) - Java (
.java) - C/C++ (
.c,.cpp,.h,.hpp)
Set the RUST_LOG environment variable to control logging:
RUST_LOG=info ./target/release/smart-diff-mcp
RUST_LOG=debug ./target/release/smart-diff-mcpRun in development mode:
cargo run -p smart-diff-mcp-serverRun tests:
cargo test -p smart-diff-mcp-serverMIT License - see LICENSE file for details