@agentguard47/mcp-server 0.1.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/LICENSE +21 -0
- package/dist/client.d.ts +49 -0
- package/dist/client.js +46 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +58 -0
- package/dist/tools.d.ts +12 -0
- package/dist/tools.js +128 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgentGuard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare class AgentGuardClient {
|
|
2
|
+
private baseUrl;
|
|
3
|
+
private apiKey;
|
|
4
|
+
constructor();
|
|
5
|
+
private fetch;
|
|
6
|
+
getTraces(opts?: {
|
|
7
|
+
limit?: string;
|
|
8
|
+
offset?: string;
|
|
9
|
+
service?: string;
|
|
10
|
+
since?: string;
|
|
11
|
+
until?: string;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
traces: unknown[];
|
|
14
|
+
}>;
|
|
15
|
+
getTrace(traceId: string): Promise<{
|
|
16
|
+
trace_id: string;
|
|
17
|
+
events: unknown[];
|
|
18
|
+
}>;
|
|
19
|
+
getAlerts(opts?: {
|
|
20
|
+
limit?: string;
|
|
21
|
+
since?: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
alerts: unknown[];
|
|
24
|
+
}>;
|
|
25
|
+
getUsage(): Promise<{
|
|
26
|
+
plan: string;
|
|
27
|
+
current_month: string;
|
|
28
|
+
event_count: number;
|
|
29
|
+
event_limit: number;
|
|
30
|
+
retention_days: number;
|
|
31
|
+
max_keys: number;
|
|
32
|
+
max_users: number;
|
|
33
|
+
}>;
|
|
34
|
+
getCosts(): Promise<{
|
|
35
|
+
monthly: {
|
|
36
|
+
total_cost: number;
|
|
37
|
+
trace_count: number;
|
|
38
|
+
};
|
|
39
|
+
by_model: Array<{
|
|
40
|
+
model: string;
|
|
41
|
+
total_cost: number;
|
|
42
|
+
call_count: number;
|
|
43
|
+
}>;
|
|
44
|
+
savings: {
|
|
45
|
+
guard_events: number;
|
|
46
|
+
estimated_savings: number;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const DEFAULT_URL = "https://agentguard.dev";
|
|
2
|
+
export class AgentGuardClient {
|
|
3
|
+
baseUrl;
|
|
4
|
+
apiKey;
|
|
5
|
+
constructor() {
|
|
6
|
+
const apiKey = process.env.AGENTGUARD_API_KEY;
|
|
7
|
+
if (!apiKey) {
|
|
8
|
+
throw new Error("AGENTGUARD_API_KEY environment variable is required. " +
|
|
9
|
+
"Generate one at your AgentGuard dashboard under Settings > API Keys.");
|
|
10
|
+
}
|
|
11
|
+
this.apiKey = apiKey;
|
|
12
|
+
this.baseUrl = (process.env.AGENTGUARD_URL || DEFAULT_URL).replace(/\/$/, "");
|
|
13
|
+
}
|
|
14
|
+
async fetch(path, params) {
|
|
15
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
16
|
+
if (params) {
|
|
17
|
+
for (const [key, value] of Object.entries(params)) {
|
|
18
|
+
if (value)
|
|
19
|
+
url.searchParams.set(key, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const res = await fetch(url.toString(), {
|
|
23
|
+
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const body = await res.text();
|
|
27
|
+
throw new Error(`AgentGuard API error (${res.status}): ${body}`);
|
|
28
|
+
}
|
|
29
|
+
return res.json();
|
|
30
|
+
}
|
|
31
|
+
async getTraces(opts) {
|
|
32
|
+
return this.fetch("/api/v1/traces", opts);
|
|
33
|
+
}
|
|
34
|
+
async getTrace(traceId) {
|
|
35
|
+
return this.fetch(`/api/v1/traces/${encodeURIComponent(traceId)}`);
|
|
36
|
+
}
|
|
37
|
+
async getAlerts(opts) {
|
|
38
|
+
return this.fetch("/api/v1/alerts", opts);
|
|
39
|
+
}
|
|
40
|
+
async getUsage() {
|
|
41
|
+
return this.fetch("/api/v1/usage");
|
|
42
|
+
}
|
|
43
|
+
async getCosts() {
|
|
44
|
+
return this.fetch("/api/v1/costs");
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
import { AgentGuardClient } from "./client.js";
|
|
6
|
+
import { tools } from "./tools.js";
|
|
7
|
+
const server = new McpServer({
|
|
8
|
+
name: "agentguard",
|
|
9
|
+
version: "0.1.0",
|
|
10
|
+
});
|
|
11
|
+
let client;
|
|
12
|
+
try {
|
|
13
|
+
client = new AgentGuardClient();
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(err.message);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
// Register each tool with the MCP server
|
|
20
|
+
for (const tool of tools) {
|
|
21
|
+
// Build a Zod schema from the JSON Schema properties
|
|
22
|
+
const shape = {};
|
|
23
|
+
const required = new Set(tool.inputSchema.required ?? []);
|
|
24
|
+
for (const [key, prop] of Object.entries(tool.inputSchema.properties)) {
|
|
25
|
+
const p = prop;
|
|
26
|
+
let field;
|
|
27
|
+
if (p.type === "number") {
|
|
28
|
+
field = z.number().describe(p.description ?? "");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
field = z.string().describe(p.description ?? "");
|
|
32
|
+
}
|
|
33
|
+
shape[key] = required.has(key) ? field : field.optional();
|
|
34
|
+
}
|
|
35
|
+
const toolName = tool.name;
|
|
36
|
+
const handler = tool.handler;
|
|
37
|
+
server.tool(toolName, tool.description, shape, async (args) => {
|
|
38
|
+
try {
|
|
39
|
+
const text = await handler(client, args);
|
|
40
|
+
return { content: [{ type: "text", text }] };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
44
|
+
return {
|
|
45
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
46
|
+
isError: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function main() {
|
|
52
|
+
const transport = new StdioServerTransport();
|
|
53
|
+
await server.connect(transport);
|
|
54
|
+
}
|
|
55
|
+
main().catch((err) => {
|
|
56
|
+
console.error("Fatal:", err);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AgentGuardClient } from "./client.js";
|
|
2
|
+
export interface ToolDefinition {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: Record<string, unknown>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
};
|
|
10
|
+
handler: (client: AgentGuardClient, args: Record<string, unknown>) => Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare const tools: ToolDefinition[];
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export const tools = [
|
|
2
|
+
{
|
|
3
|
+
name: "query_traces",
|
|
4
|
+
description: "Search recent traces from your AgentGuard-instrumented agents. " +
|
|
5
|
+
"Filter by service name, time range, or paginate through results.",
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
limit: { type: "number", description: "Max traces to return (default 20, max 500)" },
|
|
10
|
+
offset: { type: "number", description: "Offset for pagination" },
|
|
11
|
+
service: { type: "string", description: "Filter by service name" },
|
|
12
|
+
since: { type: "string", description: "ISO timestamp — only traces after this time" },
|
|
13
|
+
until: { type: "string", description: "ISO timestamp — only traces before this time" },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
handler: async (client, args) => {
|
|
17
|
+
const result = await client.getTraces({
|
|
18
|
+
limit: args.limit ? String(args.limit) : "20",
|
|
19
|
+
offset: args.offset ? String(args.offset) : undefined,
|
|
20
|
+
service: args.service,
|
|
21
|
+
since: args.since,
|
|
22
|
+
until: args.until,
|
|
23
|
+
});
|
|
24
|
+
return JSON.stringify(result, null, 2);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "get_trace",
|
|
29
|
+
description: "Get the full event tree for a specific trace by its trace ID. " +
|
|
30
|
+
"Shows all spans, tool calls, LLM calls, guard triggers, and errors.",
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
trace_id: { type: "string", description: "The trace ID to look up" },
|
|
35
|
+
},
|
|
36
|
+
required: ["trace_id"],
|
|
37
|
+
},
|
|
38
|
+
handler: async (client, args) => {
|
|
39
|
+
const result = await client.getTrace(args.trace_id);
|
|
40
|
+
return JSON.stringify(result, null, 2);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "get_alerts",
|
|
45
|
+
description: "Get recent guard alerts (loop detection, budget exceeded) and errors. " +
|
|
46
|
+
"Useful for checking if your agents are hitting safety limits.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
limit: { type: "number", description: "Max alerts to return (default 50)" },
|
|
51
|
+
since: { type: "string", description: "ISO timestamp — only alerts after this time" },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
handler: async (client, args) => {
|
|
55
|
+
const result = await client.getAlerts({
|
|
56
|
+
limit: args.limit ? String(args.limit) : undefined,
|
|
57
|
+
since: args.since,
|
|
58
|
+
});
|
|
59
|
+
return JSON.stringify(result, null, 2);
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "get_usage",
|
|
64
|
+
description: "Check your current event quota usage and plan limits. " +
|
|
65
|
+
"Shows event count vs limit, retention period, and plan details.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {},
|
|
69
|
+
},
|
|
70
|
+
handler: async (client) => {
|
|
71
|
+
const result = await client.getUsage();
|
|
72
|
+
const pct = result.event_limit > 0
|
|
73
|
+
? ((result.event_count / result.event_limit) * 100).toFixed(1)
|
|
74
|
+
: "0";
|
|
75
|
+
return JSON.stringify({ ...result, usage_percent: `${pct}%` }, null, 2);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "get_costs",
|
|
80
|
+
description: "Get cost breakdown for the current month: total spend, cost by model, " +
|
|
81
|
+
"and estimated savings from guard interventions.",
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: {},
|
|
85
|
+
},
|
|
86
|
+
handler: async (client) => {
|
|
87
|
+
const result = await client.getCosts();
|
|
88
|
+
return JSON.stringify(result, null, 2);
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "check_budget",
|
|
93
|
+
description: "Quick pass/fail budget health check. Combines usage quota and cost data " +
|
|
94
|
+
"to give a summary of whether you're within safe operating limits.",
|
|
95
|
+
inputSchema: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: {},
|
|
98
|
+
},
|
|
99
|
+
handler: async (client) => {
|
|
100
|
+
const [usage, costs] = await Promise.all([
|
|
101
|
+
client.getUsage(),
|
|
102
|
+
client.getCosts(),
|
|
103
|
+
]);
|
|
104
|
+
const usagePct = usage.event_limit > 0
|
|
105
|
+
? (usage.event_count / usage.event_limit) * 100
|
|
106
|
+
: 0;
|
|
107
|
+
const status = usagePct >= 90
|
|
108
|
+
? "critical"
|
|
109
|
+
: usagePct >= 75
|
|
110
|
+
? "warning"
|
|
111
|
+
: "healthy";
|
|
112
|
+
return JSON.stringify({
|
|
113
|
+
status,
|
|
114
|
+
plan: usage.plan,
|
|
115
|
+
events: {
|
|
116
|
+
used: usage.event_count,
|
|
117
|
+
limit: usage.event_limit,
|
|
118
|
+
percent: `${usagePct.toFixed(1)}%`,
|
|
119
|
+
},
|
|
120
|
+
costs: {
|
|
121
|
+
monthly_total: costs.monthly.total_cost,
|
|
122
|
+
trace_count: costs.monthly.trace_count,
|
|
123
|
+
},
|
|
124
|
+
savings: costs.savings,
|
|
125
|
+
}, null, 2);
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentguard47/mcp-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for AgentGuard — query traces, alerts, usage, and costs from AI coding agents",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agentguard-mcp": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch",
|
|
16
|
+
"start": "node dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^25.2.2",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|