Skip to content

Commit a6c3f6f

Browse files
dcramerclaude
andauthored
refactor: simplify use_sentry tool by removing constraint parameters (#599)
Remove organizationSlug, projectSlug, and regionUrl parameters from use_sentry tool. The tool now uses context constraints directly without merging user-provided overrides. Also add benchmark-agent.sh script for comparing direct vs agent mode performance, and remove UserPromptSubmit hook from Claude settings. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d440132 commit a6c3f6f

7 files changed

Lines changed: 117 additions & 89 deletions

File tree

‎.claude/settings.json‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121
],
2222
"deny": []
2323
},
24-
"hooks": {
25-
"UserPromptSubmit": [
26-
{
27-
"matcher": "*",
28-
"hooks": [
29-
{
30-
"type": "command",
31-
"command": "echo 'MANDATORY: If something is unclear, you MUST ask me. ALWAYS reference our docs when they are available for a task, and make a note when they arent.'"
32-
}
33-
]
34-
}
35-
]
36-
},
3724
"enableAllProjectMcpServers": true,
3825
"includeCoAuthoredBy": true,
3926
"enabledMcpjsonServers": ["sentry"]

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pnpm run generate-otel-namespaces # Update OpenTelemetry docs
6767

6868
# Manual Testing (preferred for testing MCP changes)
6969
pnpm -w run cli "who am I?" # Test with local dev server (default)
70-
pnpm -w run cli --agent "who am I?" # Test agent mode (use_sentry tool)
70+
pnpm -w run cli --agent "who am I?" # Test agent mode (use_sentry tool) - approximately 2x slower
7171
pnpm -w run cli --mcp-host=https://mcp.sentry.dev "query" # Test against production
7272
pnpm -w run cli --access-token=TOKEN "query" # Test with local stdio mode
7373

‎benchmark-agent.sh‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# Benchmark script for comparing direct vs agent mode performance
4+
# Usage: ./benchmark-agent.sh [iterations]
5+
6+
ITERATIONS=${1:-10}
7+
QUERY="what organizations do I have access to?"
8+
9+
echo "=========================================="
10+
echo "MCP Agent Performance Benchmark"
11+
echo "=========================================="
12+
echo "Query: $QUERY"
13+
echo "Iterations: $ITERATIONS"
14+
echo ""
15+
16+
# Arrays to store timings
17+
declare -a direct_times
18+
declare -a agent_times
19+
20+
echo "Running direct mode tests..."
21+
for i in $(seq 1 $ITERATIONS); do
22+
echo -n " Run $i/$ITERATIONS... "
23+
24+
# Run and capture timing (real time in seconds)
25+
START=$(date +%s.%N)
26+
pnpm -w run cli "$QUERY" > /dev/null 2>&1
27+
END=$(date +%s.%N)
28+
29+
# Calculate duration
30+
DURATION=$(echo "$END - $START" | bc)
31+
direct_times+=($DURATION)
32+
33+
echo "${DURATION}s"
34+
done
35+
36+
echo ""
37+
echo "Running agent mode tests..."
38+
for i in $(seq 1 $ITERATIONS); do
39+
echo -n " Run $i/$ITERATIONS... "
40+
41+
# Run and capture timing
42+
START=$(date +%s.%N)
43+
pnpm -w run cli --agent "$QUERY" > /dev/null 2>&1
44+
END=$(date +%s.%N)
45+
46+
# Calculate duration
47+
DURATION=$(echo "$END - $START" | bc)
48+
agent_times+=($DURATION)
49+
50+
echo "${DURATION}s"
51+
done
52+
53+
echo ""
54+
echo "=========================================="
55+
echo "Results"
56+
echo "=========================================="
57+
58+
# Calculate statistics for direct mode
59+
direct_sum=0
60+
direct_min=${direct_times[0]}
61+
direct_max=${direct_times[0]}
62+
for time in "${direct_times[@]}"; do
63+
direct_sum=$(echo "$direct_sum + $time" | bc)
64+
if (( $(echo "$time < $direct_min" | bc -l) )); then
65+
direct_min=$time
66+
fi
67+
if (( $(echo "$time > $direct_max" | bc -l) )); then
68+
direct_max=$time
69+
fi
70+
done
71+
direct_avg=$(echo "scale=2; $direct_sum / $ITERATIONS" | bc)
72+
73+
# Calculate statistics for agent mode
74+
agent_sum=0
75+
agent_min=${agent_times[0]}
76+
agent_max=${agent_times[0]}
77+
for time in "${agent_times[@]}"; do
78+
agent_sum=$(echo "$agent_sum + $time" | bc)
79+
if (( $(echo "$time < $agent_min" | bc -l) )); then
80+
agent_min=$time
81+
fi
82+
if (( $(echo "$time > $agent_max" | bc -l) )); then
83+
agent_max=$time
84+
fi
85+
done
86+
agent_avg=$(echo "scale=2; $agent_sum / $ITERATIONS" | bc)
87+
88+
# Calculate difference
89+
diff=$(echo "scale=2; $agent_avg - $direct_avg" | bc)
90+
percent=$(echo "scale=1; ($agent_avg - $direct_avg) / $direct_avg * 100" | bc)
91+
92+
echo ""
93+
echo "Direct Mode:"
94+
echo " Min: ${direct_min}s"
95+
echo " Max: ${direct_max}s"
96+
echo " Average: ${direct_avg}s"
97+
echo ""
98+
echo "Agent Mode:"
99+
echo " Min: ${agent_min}s"
100+
echo " Max: ${agent_max}s"
101+
echo " Average: ${agent_avg}s"
102+
echo ""
103+
echo "Difference:"
104+
echo " +${diff}s (${percent}% slower)"
105+
echo ""
106+
107+
# Show all individual results
108+
echo "All timings:"
109+
echo " Direct: ${direct_times[*]}"
110+
echo " Agent: ${agent_times[*]}"

‎docs/testing.mdc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Interactive testing with the MCP test client (preferred for testing MCP changes)
8888
# Test with local dev server (default: http://localhost:5173)
8989
pnpm -w run cli "who am I?"
9090

91-
# Test agent mode (use_sentry tool only)
91+
# Test agent mode (use_sentry tool only) - approximately 2x slower
9292
pnpm -w run cli --agent "who am I?"
9393

9494
# Test against production

‎packages/mcp-cloudflare/src/client/components/fragments/remote-setup.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default function RemoteSetup() {
6868
<strong>Agent Mode:</strong> Reduce context by exposing a single{" "}
6969
<code>use_sentry</code> tool instead of individual tools. The embedded
7070
AI agent handles natural language requests and automatically chains
71-
tool calls as needed.
71+
tool calls as needed. Note: Agent mode approximately doubles response
72+
time due to the embedded AI layer.
7273
</p>
7374
<ul>
7475
<li>

‎packages/mcp-server/src/tools/use-sentry/handler.test.ts‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -113,47 +113,6 @@ describe("use_sentry handler", () => {
113113
expect(toolNames).toHaveLength(19);
114114
});
115115

116-
it("handles requests with organization slug parameter", async () => {
117-
mockUseSentryAgent.mockResolvedValue({
118-
result: {
119-
result: "Found errors in my-org",
120-
},
121-
toolCalls: [],
122-
});
123-
124-
const result = await useSentry.handler(
125-
{
126-
request: "Find errors in my-org",
127-
organizationSlug: "my-org",
128-
},
129-
mockContext,
130-
);
131-
132-
expect(mockUseSentryAgent).toHaveBeenCalled();
133-
expect(result).toBe("Found errors in my-org");
134-
});
135-
136-
it("handles requests with project slug parameter", async () => {
137-
mockUseSentryAgent.mockResolvedValue({
138-
result: {
139-
result: "Issues in frontend project",
140-
},
141-
toolCalls: [],
142-
});
143-
144-
const result = await useSentry.handler(
145-
{
146-
request: "Show issues in frontend project",
147-
organizationSlug: "my-org",
148-
projectSlug: "frontend",
149-
},
150-
mockContext,
151-
);
152-
153-
expect(mockUseSentryAgent).toHaveBeenCalled();
154-
expect(result).toBe("Issues in frontend project");
155-
});
156-
157116
it("wraps tools with session constraints", async () => {
158117
const constrainedContext: ServerContext = {
159118
...mockContext,

‎packages/mcp-server/src/tools/use-sentry/handler.ts‎

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { z } from "zod";
2-
import { setTag } from "@sentry/core";
32
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
43
import { experimental_createMCPClient } from "ai";
54
import { defineTool } from "../../internal/tool-helpers/define";
65
import type { ServerContext } from "../../types";
7-
import {
8-
ParamOrganizationSlug,
9-
ParamRegionUrl,
10-
ParamProjectSlug,
11-
} from "../../schema";
126
import { useSentryAgent } from "./agent";
137
import { buildServer } from "../../server";
148
import { serverContextStorage } from "../../internal/context-storage";
@@ -58,9 +52,6 @@ export default defineTool({
5852
.describe(
5953
"The user's raw input. Do not interpret the prompt in any way. Do not add any additional information to the prompt.",
6054
),
61-
organizationSlug: ParamOrganizationSlug.optional(),
62-
projectSlug: ParamProjectSlug.optional(),
63-
regionUrl: ParamRegionUrl.optional(),
6455
trace: z
6556
.boolean()
6657
.optional()
@@ -73,26 +64,6 @@ export default defineTool({
7364
openWorldHint: true,
7465
},
7566
async handler(params, context: ServerContext) {
76-
// Set tags for monitoring
77-
if (params.organizationSlug) {
78-
setTag("organization.slug", params.organizationSlug);
79-
}
80-
if (params.projectSlug) {
81-
setTag("project.slug", params.projectSlug);
82-
}
83-
84-
// Create context with updated constraints from user parameters
85-
// This ensures the embedded agent respects org/project constraints
86-
const contextWithConstraints: ServerContext = {
87-
...context,
88-
constraints: {
89-
organizationSlug:
90-
params.organizationSlug || context.constraints.organizationSlug,
91-
projectSlug: params.projectSlug || context.constraints.projectSlug,
92-
regionUrl: params.regionUrl || context.constraints.regionUrl,
93-
},
94-
};
95-
9667
// Create linked pair of in-memory transports for client-server communication
9768
const [clientTransport, serverTransport] =
9869
InMemoryTransport.createLinkedPair();
@@ -101,15 +72,15 @@ export default defineTool({
10172
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10273
const { use_sentry, ...toolsForAgent } = tools;
10374

104-
// Build internal MCP server with constrained context
75+
// Build internal MCP server with the provided context
10576
const server = buildServer({
106-
context: contextWithConstraints,
77+
context,
10778
tools: toolsForAgent,
10879
});
10980

11081
// Run all MCP operations within the ServerContext
11182
// This ensures tools invoked through the MCP protocol have access to the context
112-
return await serverContextStorage.run(contextWithConstraints, async () => {
83+
return await serverContextStorage.run(context, async () => {
11384
// Connect server to its transport
11485
await server.server.connect(serverTransport);
11586

0 commit comments

Comments
 (0)