Skip to content

Commit 5494172

Browse files
authored
Improve workers observability MCP (#84)
* Add prompt to better handle multi account users * replace javascript with prompts * format setActiveAccount method * more workers observability prompt improvements * remove the old workers logs api * remove the old workers logs tool * improve the keys and values tool descriptions * remove unecessary log * try prevent extra responses * try prevent extra responses * improve calculations * improve calculations * formatting
1 parent c56484c commit 5494172

File tree

9 files changed

+486
-981
lines changed

9 files changed

+486
-981
lines changed

apps/workers-observability/src/index.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
1414
import { registerWorkersTools } from '@repo/mcp-common/src/tools/worker'
1515

1616
import { MetricsTracker } from '../../../packages/mcp-observability/src'
17-
import { registerLogsTools } from './tools/logs'
17+
import { registerObservabilityTools } from './tools/observability'
1818

1919
import type { AccountSchema, UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
2020
import type { Env } from './context'
@@ -51,10 +51,6 @@ export class ObservabilityMCP extends McpAgent<Env, State, Props> {
5151
return this._server
5252
}
5353

54-
constructor(ctx: DurableObjectState, env: Env) {
55-
super(ctx, env)
56-
}
57-
5854
async init() {
5955
this.server = new CloudflareMCPServer({
6056
userId: this.props.user.id,
@@ -64,6 +60,30 @@ export class ObservabilityMCP extends McpAgent<Env, State, Props> {
6460
version: this.env.MCP_SERVER_VERSION,
6561
},
6662
sentry: initSentryWithUser(env, this.ctx, this.props.user.id),
63+
options: {
64+
instructions: `# Cloudflare Workers Observability Tool
65+
66+
This tool provides powerful capabilities to analyze and troubleshoot your Cloudflare Workers through logs and metrics. Here's how to use it effectively:
67+
68+
## IMPORTANT: Query Discipline
69+
70+
**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.
71+
72+
## Best Practices
73+
74+
### Efficient Querying
75+
- Start with a focused query that's most likely to answer the question
76+
- Review results completely before deciding if additional queries are needed
77+
- If the first query provides the answer, STOP and present it to the user
78+
- Only run additional queries when specifically directed or when essential information is missing
79+
80+
### When to STOP Querying
81+
- STOP after presenting meaningful results from the first query
82+
- STOP when you've answered the user's specific question
83+
- STOP when the user hasn't requested additional exploration
84+
- Only continue if explicitly directed with "EXPLORE" or similar instruction
85+
`,
86+
},
6787
})
6888

6989
registerAccountTools(this)
@@ -72,7 +92,7 @@ export class ObservabilityMCP extends McpAgent<Env, State, Props> {
7292
registerWorkersTools(this)
7393

7494
// Register Cloudflare Workers logs tools
75-
registerLogsTools(this)
95+
registerObservabilityTools(this)
7696
}
7797

7898
async getActiveAccountId() {

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

Lines changed: 0 additions & 310 deletions
This file was deleted.

0 commit comments

Comments
 (0)