You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No annotations, no decorators, no boilerplate. Your existing Click CLI *is* the MCP server.
50
+
51
+
## MCP Workflow with AI Coding Agents
52
+
53
+
This section shows how to integrate click-to-mcp with popular AI coding tools so your CLIs become first-class tools that AI agents can invoke directly.
54
+
55
+
### Claude Code
56
+
57
+
Add your CLI as an MCP server in your project's `.claude/settings.json`:
58
+
59
+
```json
60
+
{
61
+
"mcpServers": {
62
+
"api-contract-guardian": {
63
+
"command": "click-to-mcp",
64
+
"args": ["serve", "api-contract-guardian"]
65
+
},
66
+
"json2sql": {
67
+
"command": "click-to-mcp",
68
+
"args": ["serve", "json2sql"]
69
+
},
70
+
"deploydiff": {
71
+
"command": "click-to-mcp",
72
+
"args": ["serve", "deploydiff"]
73
+
}
74
+
}
75
+
}
76
+
```
77
+
78
+
Now when you ask Claude Code to "validate my API contracts", it will automatically call the `acg_validate` MCP tool with the right arguments — no manual command-line invocation needed.
79
+
80
+
### Cursor
81
+
82
+
Add to your Cursor MCP settings (`.cursor/mcp.json`):
83
+
84
+
```json
85
+
{
86
+
"mcpServers": {
87
+
"api-contract-guardian": {
88
+
"command": "click-to-mcp",
89
+
"args": ["serve", "api-contract-guardian"]
90
+
}
91
+
}
92
+
}
93
+
```
94
+
95
+
### Cline / VS Code
96
+
97
+
Add to `.vscode/mcp.json`:
98
+
99
+
```json
100
+
{
101
+
"servers": {
102
+
"api-contract-guardian": {
103
+
"command": "click-to-mcp",
104
+
"args": ["serve", "api-contract-guardian"]
105
+
}
106
+
}
107
+
}
108
+
```
109
+
110
+
### Custom Integration (Programmatic)
111
+
112
+
For CLIs that aren't installed as entry points, use the library API:
113
+
114
+
```python
115
+
# my_mcp_server.py
116
+
from click_to_mcp import run
117
+
from my_cli import app # Your Click/typer CLI
118
+
119
+
run(app, prefix="my-cli", name="my-cli-mcp")
120
+
```
121
+
122
+
Then reference the script directly:
123
+
124
+
```json
125
+
{
126
+
"mcpServers": {
127
+
"my-cli": {
128
+
"command": "python",
129
+
"args": ["my_mcp_server.py"]
130
+
}
131
+
}
132
+
}
133
+
```
134
+
135
+
### What the Agent Sees
136
+
137
+
When your MCP server is configured, the AI agent sees your CLI commands as native tools. For example, with api-contract-guardian:
138
+
139
+
```
140
+
Agent: "I need to validate the API contract against the staging server."
← Result: "Validating openapi.yaml against https://staging.api.com...\n✓ All contracts pass"
144
+
```
145
+
146
+
The agent doesn't need to know shell syntax, argument flags, or command names. It just calls the tool with structured arguments, and click-to-mcp handles the rest.
147
+
148
+
## Examples
149
+
150
+
### Quick Start (3 lines)
151
+
152
+
```python
153
+
import click
154
+
from click_to_mcp import run
155
+
156
+
@click.group()
157
+
defmy_cli():
158
+
"""My awesome CLI tool."""
159
+
pass
160
+
161
+
@my_cli.command()
162
+
@click.argument("name")
163
+
@click.option("--loud", is_flag=True, help="Shout the greeting")
164
+
defhello(name: str, loud: bool):
165
+
"""Say hello to someone."""
166
+
msg =f"Hello, {name}!"
167
+
if loud:
168
+
msg = msg.upper()
169
+
click.echo(msg)
170
+
171
+
if__name__=="__main__":
172
+
run(my_cli, prefix="my-cli", name="my-cli-mcp")
173
+
```
174
+
175
+
See [examples/quick_start.py](examples/quick_start.py) for the full runnable example.
176
+
177
+
### Wrapping api-contract-guardian
178
+
179
+
See [examples/api_contract_guardian_mcp.py](examples/api_contract_guardian_mcp.py) for a demo showing how to wrap API Contract Guardian as an MCP server with `validate`, `extract`, and `monitor` commands.
180
+
37
181
## Usage
38
182
39
183
### CLI — Discover and Serve
@@ -127,9 +271,9 @@ Then agents can use it as: `your-cli mcp`
0 commit comments