|
2 | 2 |
|
3 | 3 | The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is an open standard that allows AI assistants to interact with external tools and data sources. The `pred` CLI includes a built-in MCP server that exposes the full reduction graph, problem creation, solving, and reduction capabilities to any MCP-compatible AI assistant (such as Claude Code, Cursor, Windsurf, or OpenCode). |
4 | 4 |
|
| 5 | +## Walkthrough |
| 6 | + |
| 7 | +A complete session showing how an AI assistant uses MCP tools behind the scenes to answer your questions. |
| 8 | + |
| 9 | +**You:** Create a weighted MIS problem on a 4-vertex graph with edges 0-1, 1-2, 2-3, 3-0, 0-2 and weights [1, 2, 3, 4], explain the result. |
| 10 | + |
| 11 | +> **Assistant:** I created a Maximum Independent Set instance on a SimpleGraph with 4 vertices, 5 edges, and integer weights [1, 2, 3, 4]. Each vertex has a weight, and the goal is to find a subset of non-adjacent vertices that maximizes total weight. |
| 12 | +
|
| 13 | +**You:** What can I do with this problem? Explain the result. |
| 14 | + |
| 15 | +> **Assistant:** This instance has 4 binary variables (one per vertex). It can be reduced to 5 other problem types: ILP, MaximumSetPacking, MinimumVertexCover, QUBO, and other MIS variants. You can solve it directly using either an ILP solver or brute-force search. |
| 16 | +
|
| 17 | +**You:** Check if selecting vertices 1 and 3 is a valid solution, explain the result. |
| 18 | + |
| 19 | +> **Assistant:** Yes! Selecting vertices 1 and 3 (configuration [0,1,0,1]) is a valid independent set — these two vertices are not adjacent. The total weight is 2 + 4 = 6. |
| 20 | +
|
| 21 | +**You:** Reduce this to QUBO, explain the result. |
| 22 | + |
| 23 | +> **Assistant:** Done. The MIS instance was transformed into a 4x4 QUBO matrix: |
| 24 | +> |
| 25 | +> ``` |
| 26 | +> [-1.0, 11.0, 11.0, 11.0] |
| 27 | +> [ 0.0, -2.0, 11.0, 0.0] |
| 28 | +> [ 0.0, 0.0, -3.0, 11.0] |
| 29 | +> [ 0.0, 0.0, 0.0, -4.0] |
| 30 | +> ``` |
| 31 | +> |
| 32 | +> The diagonal entries (-1, -2, -3, -4) encode vertex weights negated for minimization. The off-diagonal entries (11.0) are large penalties on edges — selecting two adjacent vertices would incur a penalty that outweighs any benefit. The reduction path is: MaximumIndependentSet → QUBO. |
| 33 | +
|
| 34 | +**You:** Now solve it through the reduction, explain the result. |
| 35 | +
|
| 36 | +> **Assistant:** The brute-force solver found the optimal solution by solving the QUBO, then mapping the result back to the original MIS: |
| 37 | +> |
| 38 | +> - **QUBO solution:** [0,1,0,1] with objective -6.0 (minimization) |
| 39 | +> - **MIS solution:** vertices {1, 3} with weight **6** (maximization) |
| 40 | +> |
| 41 | +> The QUBO objective of -6.0 corresponds to the MIS maximum of 6 — the reduction correctly inverts the sign. This confirms that {1, 3} is the optimal independent set. |
| 42 | +
|
5 | 43 | ## Installation |
6 | 44 |
|
7 | | -### Via cargo |
| 45 | +Install via cargo: |
8 | 46 |
|
9 | 47 | ```bash |
10 | 48 | cargo install problemreductions-cli |
11 | 49 | ``` |
12 | 50 |
|
13 | | -### From source |
| 51 | +Or build from source: |
14 | 52 |
|
15 | 53 | ```bash |
16 | 54 | git clone https://github.com/CodingThrust/problem-reductions |
17 | 55 | cd problem-reductions |
18 | | -make cli # builds target/release/pred |
| 56 | +make cli # builds and installs target/release/pred |
19 | 57 | ``` |
20 | 58 |
|
21 | 59 | ## Configuration |
22 | 60 |
|
23 | | -### Claude Code / Claude Desktop |
| 61 | +### Claude Code |
24 | 62 |
|
25 | | -Add to your project's `.mcp.json` (or `~/.claude/mcp.json` for global): |
| 63 | +```bash |
| 64 | +# Project-scoped (current project only) |
| 65 | +claude mcp add --scope project problemreductions -- pred mcp |
26 | 66 |
|
27 | | -```json |
28 | | -{ |
29 | | - "mcpServers": { |
30 | | - "problemreductions": { |
31 | | - "command": "pred", |
32 | | - "args": ["mcp"] |
33 | | - } |
34 | | - } |
35 | | -} |
| 67 | +# User-scoped (all projects) |
| 68 | +claude mcp add --scope user problemreductions -- pred mcp |
36 | 69 | ``` |
37 | 70 |
|
38 | | -### Cursor |
| 71 | +### Cursor / Windsurf |
39 | 72 |
|
40 | | -Add to `.cursor/mcp.json` in your project root (or `~/.cursor/mcp.json` for global): |
| 73 | +Add to the appropriate config file: |
| 74 | +- **Cursor:** `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global) |
| 75 | +- **Windsurf:** `~/.codeium/windsurf/mcp_config.json` |
41 | 76 |
|
42 | 77 | ```json |
43 | | -{ |
44 | | - "mcpServers": { |
45 | | - "problemreductions": { |
46 | | - "command": "pred", |
47 | | - "args": ["mcp"] |
48 | | - } |
49 | | - } |
50 | | -} |
51 | | -``` |
52 | | - |
53 | | -### Windsurf |
54 | | - |
55 | | -Add to `~/.codeium/windsurf/mcp_config.json`: |
56 | | - |
57 | | -```json |
58 | | -{ |
59 | | - "mcpServers": { |
60 | | - "problemreductions": { |
61 | | - "command": "pred", |
62 | | - "args": ["mcp"] |
63 | | - } |
64 | | - } |
65 | | -} |
| 78 | +{ "mcpServers": { "problemreductions": { "command": "pred", "args": ["mcp"] } } } |
66 | 79 | ``` |
67 | 80 |
|
68 | 81 | ### OpenCode |
69 | 82 |
|
70 | 83 | Add to `opencode.json` in your project root: |
71 | 84 |
|
72 | 85 | ```json |
73 | | -{ |
74 | | - "mcp": { |
75 | | - "problemreductions": { |
76 | | - "type": "local", |
77 | | - "command": ["pred", "mcp"] |
78 | | - } |
79 | | - } |
80 | | -} |
| 86 | +{ "mcp": { "problemreductions": { "type": "local", "command": ["pred", "mcp"] } } } |
81 | 87 | ``` |
82 | 88 |
|
83 | 89 | ### Generic MCP Client |
84 | 90 |
|
85 | | -Any MCP client that supports the stdio transport can connect to the server by running: |
86 | | - |
87 | | -```bash |
88 | | -pred mcp |
89 | | -``` |
90 | | - |
91 | | -The server communicates over stdin/stdout using the MCP JSON-RPC protocol. |
| 91 | +Any MCP client that supports the stdio transport can connect by running `pred mcp`. The server communicates over stdin/stdout using the MCP JSON-RPC protocol. |
92 | 92 |
|
93 | 93 | ## Available Tools |
94 | 94 |
|
@@ -116,51 +116,14 @@ The MCP server provides 10 tools organized into two categories: **graph query to |
116 | 116 |
|
117 | 117 | ## Available Prompts |
118 | 118 |
|
119 | | -The server provides 3 prompt templates that guide the AI assistant through common workflows: |
| 119 | +The server provides 7 task-oriented prompt templates: |
120 | 120 |
|
121 | 121 | | Prompt | Arguments | Description | |
122 | 122 | |--------|-----------|-------------| |
123 | | -| `analyze_problem` | `problem_type` (required) | Analyze a problem type: show its definition, variants, size fields, and reduction edges | |
124 | | -| `reduction_walkthrough` | `source` (required), `target` (required) | End-to-end reduction walkthrough: find a path, create an instance, reduce it, and solve the result | |
125 | | -| `explore_graph` | *(none)* | Explore the reduction graph: list all problems, export the graph, and analyze its structure | |
126 | | - |
127 | | -## Example Usage |
128 | | - |
129 | | -Once configured, you can interact with the reduction graph naturally through your AI assistant: |
130 | | - |
131 | | -``` |
132 | | -> What problems can MaximumIndependentSet reduce to? |
133 | | -
|
134 | | -> Walk me through reducing a 5-vertex MIS instance to QUBO |
135 | | -
|
136 | | -> Create a random graph with 8 vertices and solve the MaxCut problem on it |
137 | | -
|
138 | | -> Find all reduction paths from Satisfiability to SpinGlass |
139 | | -``` |
140 | | - |
141 | | -The AI assistant will automatically call the appropriate MCP tools to answer your questions, create problem instances, perform reductions, and solve problems. |
142 | | - |
143 | | -## Testing with MCP Inspector |
144 | | - |
145 | | -You can test the MCP server using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector): |
146 | | - |
147 | | -```bash |
148 | | -npx @modelcontextprotocol/inspector pred mcp |
149 | | -``` |
150 | | - |
151 | | -This opens a web UI where you can: |
152 | | - |
153 | | -1. Browse the list of available tools and their schemas |
154 | | -2. Call tools with custom parameters and inspect the JSON responses |
155 | | -3. Browse and invoke prompt templates |
156 | | -4. Verify the server is working correctly before configuring your AI assistant |
157 | | - |
158 | | -## Running MCP Tests |
159 | | - |
160 | | -To run the MCP server test suite: |
161 | | - |
162 | | -```bash |
163 | | -make mcp-test |
164 | | -``` |
165 | | - |
166 | | -This runs both unit tests (tool logic) and integration tests (MCP protocol-level tool calls). |
| 123 | +| `what_is` | `problem_type` (required) | Explain a problem type | |
| 124 | +| `model_my_problem` | `description` (required) | Map a real-world problem to an NP-hard type | |
| 125 | +| `compare` | `problem_a` (required), `problem_b` (required) | Compare two problem types | |
| 126 | +| `reduce` | `source` (required), `target` (required) | Step-by-step reduction walkthrough | |
| 127 | +| `solve` | `problem_type` (required), `params` (required) | Create and solve a problem instance | |
| 128 | +| `find_reduction` | `source` (required), `target` (required) | Find the best reduction path between two problems | |
| 129 | +| `overview` | *(none)* | Explore the full landscape of NP-hard problems | |
0 commit comments