Skip to content

Commit 6224f98

Browse files
committed
try prevent extra responses
1 parent ffc6a08 commit 6224f98

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

apps/workers-observability/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ export class ObservabilityMCP extends McpAgent<Env, State, Props> {
6060
version: this.env.MCP_SERVER_VERSION,
6161
},
6262
sentry: initSentryWithUser(env, this.ctx, this.props.user.id),
63+
options: { instructions: `# Cloudflare Workers Observability Tool
64+
65+
This tool provides powerful capabilities to analyze and troubleshoot your Cloudflare Workers through logs and metrics. Here's how to use it effectively:
66+
67+
## IMPORTANT: Query Discipline
68+
69+
**STOP after the first successful query if it answers the user's question.** Do not run multiple queries unless absolutely necessary. The first query often contains the answer - review it thoroughly before running additional queries.
70+
71+
### When to STOP Querying
72+
- STOP after presenting meaningful results from the first query
73+
- STOP when you've answered the user's specific question
74+
- STOP when the user hasn't requested additional exploration
75+
- Only continue if explicitly directed with "EXPLORE" or similar instruction
76+
` },
6377
})
6478

6579
registerAccountTools(this)

apps/workers-observability/src/tools/observability.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ export function registerObservabilityTools(agent: ObservabilityMCP) {
2323
'query_worker_observability',
2424
`Query the Workers Observability API to analyze logs and metrics from your Cloudflare Workers.
2525
26+
The resulting information should answer the users query. STOP HERE and show them the answer to there question.
27+
If you can't answer the question ask for a follow up.
28+
29+
## Output handling
30+
31+
Once you have ran this query you must IMMEDIATELY present the user with this information.
32+
33+
- **Events**: Display as a table with key fields. For detailed inspection, show full JSON of individual events.
34+
- **Calculations**: Use appropriate charts based on the data (bar charts for comparisons, line charts for time series)
35+
- **Invocations**: Show full request/response details with syntax highlighting for important fields
36+
2637
## When to Use This tool
2738
2839
- Investigate errors or performance issues in your Cloudflare Workers
@@ -43,17 +54,9 @@ This tool provides three primary views of your Worker data:
4354
- Before applying filters, use the observability_keys and observability_values tools to confirm available filter fields and the correct filter value to add unless you have the data in a response from a previous query.
4455
- Common filter fields: $metadata.service, $metadata.trigger, $metadata.message, $metadata.level, $metadata.requestId,
4556
46-
## Output handling
47-
Once you have ran this query you must IMMEDIATELY present the user with this information.
48-
49-
- **Events**: Display as a table with key fields. For detailed inspection, show full JSON of individual events.
50-
- **Calculations**: Use appropriate charts based on the data (bar charts for comparisons, line charts for time series)
51-
- **Invocations**: Show full request/response details with syntax highlighting for important fields
52-
5357
## Troubleshooting
5458
- If no results are returned, suggest broadening the time range or relaxing filters
5559
- For errors about invalid fields, recommend using observability_keys to see available options
56-
- Handle rate limiting by suggesting query optimization
5760
`,
5861

5962
{

packages/mcp-common/src/types/workers-logs-schemas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ export const zQueryRunRequest = z.object({
312312
filters: z.array(zQueryFilter).optional(),
313313
filterCombination: zFilterCombination.optional(),
314314
calculations: z.array(zQueryCalculation).optional(),
315-
groupBys: z.array(zQueryGroupBy).optional(),
315+
groupBys: z.array(zQueryGroupBy).optional().describe(`Only valid when doing a Calculation`),
316316
orderBy: z
317317
.object({
318-
value: z.string(),
318+
value: z.string().describe("This must be the alias of a calculation"),
319319
order: z.enum(['asc', 'desc']).optional(),
320320
})
321-
.optional(),
321+
.optional().describe("Order By only workers when a group by is present"),
322322
limit: z
323323
.number()
324324
.int()

0 commit comments

Comments
 (0)