clawbackai-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +98 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# clawbackai-mcp
|
|
2
|
+
|
|
3
|
+
LLM cost optimization tools for AI agents via the Model Context Protocol. Audit your spend, activate smart routing, and track savings without changing your code.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
Add to your MCP client config:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"clawback": {
|
|
13
|
+
"url": "https://clawback.run/mcp"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Claude Desktop
|
|
20
|
+
|
|
21
|
+
Add to `claude_desktop_config.json`:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"clawback": {
|
|
27
|
+
"command": "npx",
|
|
28
|
+
"args": ["clawbackai-mcp"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Claude Code
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
claude mcp add clawback -- npx clawbackai-mcp
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## CrewAI
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from crewai import Agent
|
|
44
|
+
from crewai_tools import MCPServerAdapter
|
|
45
|
+
|
|
46
|
+
mcp_adapter = MCPServerAdapter({"url": "https://clawback.run/mcp"})
|
|
47
|
+
|
|
48
|
+
agent = Agent(
|
|
49
|
+
role="LLM Cost Optimizer",
|
|
50
|
+
tools=mcp_adapter.tools
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## LangGraph
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
58
|
+
|
|
59
|
+
client = MultiServerMCPClient({
|
|
60
|
+
"clawback": {
|
|
61
|
+
"url": "https://clawback.run/mcp",
|
|
62
|
+
"transport": "streamable_http",
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
tools = await client.get_tools()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Vercel AI SDK
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { experimental_createMCPClient } from "ai";
|
|
73
|
+
|
|
74
|
+
const mcp = await experimental_createMCPClient({
|
|
75
|
+
transport: { type: "sse", url: "https://clawback.run/mcp" },
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const tools = await mcp.tools();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Tools
|
|
82
|
+
|
|
83
|
+
| Tool | Description | Auth |
|
|
84
|
+
|------|-------------|------|
|
|
85
|
+
| `start_audit` | Start a free LLM cost audit. Set one env var, Clawback observes your API calls and generates a savings report. | API key |
|
|
86
|
+
| `get_audit_status` | Check audit progress, call count, report URL, and routing recommendations. | API key |
|
|
87
|
+
| `activate_routing` | Activate smart routing after audit completes. Strategies: balanced, max_savings, conservative. | API key |
|
|
88
|
+
| `optimize_llm_call` | Route a completion to the best price-performance model for the task type. | API key |
|
|
89
|
+
| `get_frontier` | Get the efficient frontier (best quality per dollar) by task type. | None |
|
|
90
|
+
| `check_savings` | Check monthly and all-time routing value. | API key |
|
|
91
|
+
| `get_model_recommendation` | Get a model recommendation for a task type without making an API call. | None |
|
|
92
|
+
| `set_agent_budget` | Set a monthly budget limit per agent with action on exceed (block, downgrade, alert). | API key |
|
|
93
|
+
|
|
94
|
+
## How it works
|
|
95
|
+
|
|
96
|
+
1. **Audit first.** Call `start_audit` to register. Set your `OPENAI_BASE_URL` to `https://clawback.run/v1`. Your API calls flow through Clawback's proxy — zero latency impact, your keys, your data.
|
|
97
|
+
|
|
98
|
+
2. **Get your report.** At 50 calls, Clawback generates an audit report. It replays your calls against cheaper models, scores quality per task type, and tells you exactly how much you can save.
|
|
99
|
+
|
|
100
|
+
3. **Activate routing.** Review the report. If the savings are real, call `activate_routing`. Every subsequent call gets routed to the optimal model on the efficient frontier.
|
|
101
|
+
|
|
102
|
+
4. **Track savings.** Use `check_savings` to see your monthly routing value. Free until routing value exceeds $500/month, then 15% of the price difference per routed call.
|
|
103
|
+
|
|
104
|
+
## Pricing
|
|
105
|
+
|
|
106
|
+
- Free audit, always
|
|
107
|
+
- Smart routing: 15% of the price difference per routed call
|
|
108
|
+
- Free until routing value exceeds $500/month
|
|
109
|
+
- You keep 85% of every dollar saved
|
|
110
|
+
|
|
111
|
+
## Links
|
|
112
|
+
|
|
113
|
+
- Website: [clawback.run](https://clawback.run)
|
|
114
|
+
- Efficient Frontier: [clawback.run/frontier](https://clawback.run/frontier)
|
|
115
|
+
- Security: [clawback.run/security](https://clawback.run/security)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const CLAWBACK_MCP_URL = "https://clawback.run/mcp";
|
|
6
|
+
async function callClawback(toolName, args) {
|
|
7
|
+
const res = await fetch(CLAWBACK_MCP_URL, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: { "Content-Type": "application/json" },
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
jsonrpc: "2.0",
|
|
12
|
+
id: Date.now(),
|
|
13
|
+
method: "tools/call",
|
|
14
|
+
params: { name: toolName, arguments: args },
|
|
15
|
+
}),
|
|
16
|
+
});
|
|
17
|
+
const body = await res.json();
|
|
18
|
+
if (body.error)
|
|
19
|
+
throw new Error(body.error.message);
|
|
20
|
+
const text = body.result?.content?.[0]?.text;
|
|
21
|
+
return text ? JSON.parse(text) : body.result;
|
|
22
|
+
}
|
|
23
|
+
const server = new McpServer({
|
|
24
|
+
name: "clawback",
|
|
25
|
+
version: "1.0.0",
|
|
26
|
+
});
|
|
27
|
+
// Step 1: Start audit
|
|
28
|
+
server.tool("start_audit", "Start a free Clawback audit. Registers your API key for traffic observation. Route 50+ calls through clawback.run/v1 to trigger the audit automatically.", {
|
|
29
|
+
api_key: z.string().describe("Your provider API key (hashed for identification, never stored raw)"),
|
|
30
|
+
email: z.string().optional().describe("Optional email for report delivery"),
|
|
31
|
+
}, async (args) => {
|
|
32
|
+
const result = await callClawback("start_audit", args);
|
|
33
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
34
|
+
});
|
|
35
|
+
// Step 2: Check audit status
|
|
36
|
+
server.tool("get_audit_status", "Check audit progress. Returns calls logged, report URL when ready, routing recommendations, and next steps. Share the report URL with a human decision maker.", {
|
|
37
|
+
api_key: z.string().describe("Your API key"),
|
|
38
|
+
}, async (args) => {
|
|
39
|
+
const result = await callClawback("get_audit_status", args);
|
|
40
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
41
|
+
});
|
|
42
|
+
// Step 3: Activate routing (after audit review)
|
|
43
|
+
server.tool("activate_routing", "Activate smart routing after reviewing audit results. Only call after get_audit_status shows a completed report.", {
|
|
44
|
+
api_key: z.string().describe("Your API key"),
|
|
45
|
+
strategy: z.enum(["balanced", "max_savings", "conservative"]).optional().describe("Routing strategy"),
|
|
46
|
+
}, async (args) => {
|
|
47
|
+
const result = await callClawback("activate_routing", args);
|
|
48
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
49
|
+
});
|
|
50
|
+
// Step 4: Use optimized routing
|
|
51
|
+
server.tool("optimize_llm_call", "Route a completion to the best model. Requires routing to be activated first via the audit flow.", {
|
|
52
|
+
model: z.string().describe("The model you would normally use"),
|
|
53
|
+
messages: z.array(z.any()).describe("OpenAI-format messages array"),
|
|
54
|
+
temperature: z.number().optional(),
|
|
55
|
+
max_tokens: z.number().int().optional(),
|
|
56
|
+
api_key: z.string().describe("Your provider API key"),
|
|
57
|
+
}, async (args) => {
|
|
58
|
+
const result = await callClawback("optimize_llm_call", args);
|
|
59
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
60
|
+
});
|
|
61
|
+
// Read-only tools (no auth required)
|
|
62
|
+
server.tool("get_frontier", "Get the efficient frontier — best quality per dollar by task type. No API key needed.", {
|
|
63
|
+
task_type: z.enum(["general", "coding", "classification"]).optional().describe("Task type"),
|
|
64
|
+
}, async (args) => {
|
|
65
|
+
const result = await callClawback("get_frontier", args);
|
|
66
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
67
|
+
});
|
|
68
|
+
server.tool("check_savings", "Check monthly and all-time routing value (price difference captured per routed call).", {
|
|
69
|
+
api_key: z.string().describe("Your API key"),
|
|
70
|
+
}, async (args) => {
|
|
71
|
+
const result = await callClawback("check_savings", args);
|
|
72
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
73
|
+
});
|
|
74
|
+
server.tool("get_model_recommendation", "Get the recommended model for a task type without making an API call. No key needed.", {
|
|
75
|
+
task_type: z.string().optional().describe("Task type"),
|
|
76
|
+
max_cost_per_million: z.number().optional().describe("Max cost per million tokens"),
|
|
77
|
+
min_quality: z.number().optional().describe("Minimum quality score (0-100)"),
|
|
78
|
+
}, async (args) => {
|
|
79
|
+
const result = await callClawback("get_model_recommendation", args);
|
|
80
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
81
|
+
});
|
|
82
|
+
server.tool("set_agent_budget", "Set per-agent monthly budget. Requires routing to be active.", {
|
|
83
|
+
api_key: z.string().describe("Your API key"),
|
|
84
|
+
agent_name: z.string().describe("Agent name"),
|
|
85
|
+
monthly_budget_usd: z.number().describe("Monthly budget in USD"),
|
|
86
|
+
action_on_exceed: z.enum(["block", "downgrade", "alert"]).optional(),
|
|
87
|
+
}, async (args) => {
|
|
88
|
+
const result = await callClawback("set_agent_budget", args);
|
|
89
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
90
|
+
});
|
|
91
|
+
async function main() {
|
|
92
|
+
const transport = new StdioServerTransport();
|
|
93
|
+
await server.connect(transport);
|
|
94
|
+
}
|
|
95
|
+
main().catch((err) => {
|
|
96
|
+
console.error("Fatal:", err);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clawbackai-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"mcpName": "io.github.Rckl88/clawbackai-mcp",
|
|
5
|
+
"description": "Clawback MCP server — LLM cost optimization tools for AI agents. Audit your LLM spend, activate smart routing, and track savings via the Model Context Protocol.",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": { "clawbackai-mcp": "dist/index.js" },
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Alex Crabbe",
|
|
12
|
+
"email": "alex@clawback.run",
|
|
13
|
+
"url": "https://clawback.run"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://clawback.run",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/Rckl88/clawbackai"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mcp",
|
|
22
|
+
"llm",
|
|
23
|
+
"cost-optimization",
|
|
24
|
+
"model-routing",
|
|
25
|
+
"ai-agents",
|
|
26
|
+
"efficient-frontier",
|
|
27
|
+
"openai",
|
|
28
|
+
"anthropic",
|
|
29
|
+
"model-context-protocol",
|
|
30
|
+
"clawback"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"start": "node dist/index.js",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "1.29.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|