Skip to content

Commit ec28ab9

Browse files
committed
2 parents f9e6923 + 5e08254 commit ec28ab9

39 files changed

+5599
-5681
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Wrangler",
5+
"type": "node",
6+
"request": "attach",
7+
"port": 9229,
8+
"cwd": "/",
9+
"resolveSourceMapLocations": null,
10+
"attachExistingChildren": false,
11+
"autoAttachChildProcesses": false,
12+
"sourceMaps": true // works with or without this line
13+
}
14+
]
15+
}

apps/cloudflare-one-casb/src/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import OAuthProvider from '@cloudflare/workers-oauth-provider'
2-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
32
import { McpAgent } from 'agents/mcp'
43
import { env } from 'cloudflare:workers'
54

65
import {
76
createAuthHandlers,
87
handleTokenExchangeCallback,
98
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
9+
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
1010
import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
1111

12+
import { MetricsTracker } from '../../../packages/mcp-observability/src'
1213
import { registerIntegrationsTools } from './tools/integrations'
1314

1415
import type { AccountSchema, UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
16+
import type { CloudflareMcpAgent } from '@repo/mcp-common/src/types/cloudflare-mcp-agent'
17+
18+
const metrics = new MetricsTracker(env.MCP_METRICS, {
19+
name: env.MCP_SERVER_NAME,
20+
version: env.MCP_SERVER_VERSION,
21+
})
1522

1623
// Context from the auth process, encrypted & stored in the auth token
1724
// and provided to the DurableMCP as this.props
@@ -23,18 +30,13 @@ export type Props = {
2330

2431
export type State = { activeAccountId: string | null }
2532
export class CASBMCP extends McpAgent<Env, State, Props> {
26-
// @ts-ignore
27-
server = new McpServer({
28-
name: "Remote MCP Server with Cloudflare One's Cloud Access Security Broker (CASB)",
29-
version: '1.0.0',
33+
server = new CloudflareMCPServer(undefined, env.MCP_METRICS, {
34+
name: env.MCP_SERVER_NAME,
35+
version: env.MCP_SERVER_VERSION,
3036
})
3137

32-
initialState: State = {
33-
activeAccountId: null,
34-
}
35-
3638
async init() {
37-
registerAccountTools(this)
39+
registerAccountTools(this as unknown as CloudflareMcpAgent)
3840
registerIntegrationsTools(this)
3941
}
4042

@@ -49,8 +51,6 @@ export class CASBMCP extends McpAgent<Env, State, Props> {
4951
}
5052

5153
setActiveAccountId(accountId: string) {
52-
console.log('Setting account ID: ', accountId)
53-
// TODO: Figure out why this fail sometimes, and why we need to wrap this in a try catch
5454
try {
5555
this.setState({
5656
...this.state,
@@ -73,7 +73,7 @@ export default new OAuthProvider({
7373
// @ts-ignore
7474
apiHandler: CASBMCP.mount('/sse'),
7575
// @ts-ignore
76-
defaultHandler: createAuthHandlers({ scopes: CloudflareOneCasbScopes }),
76+
defaultHandler: createAuthHandlers({ scopes: CloudflareOneCasbScopes, metrics }),
7777
authorizeEndpoint: '/oauth/authorize',
7878
tokenEndpoint: '/token',
7979
tokenExchangeCallback: (options) =>

apps/cloudflare-one-casb/worker-configuration.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ declare namespace Cloudflare {
66
CLOUDFLARE_CLIENT_ID: string;
77
CLOUDFLARE_CLIENT_SECRET: string;
88
MCP_OBJECT: DurableObjectNamespace<import("./src/index").CASBMCP>;
9+
10+
MCP_SERVER_NAME: "PLACEHOLDER";
11+
MCP_SERVER_VERSION: "PLACEHOLDER";
12+
MCP_METRICS: AnalyticsEngineDataset;
913
}
1014
}
1115
interface Env extends Cloudflare.Env {}

apps/cloudflare-one-casb/wrangler.jsonc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"observability": {
1717
"enabled": true
1818
},
19+
"vars": {
20+
"MCP_SERVER_NAME": "PLACEHOLDER",
21+
"MCP_SERVER_VERSION": "PLACEHOLDER"
22+
},
1923
"dev": {
2024
"port": 8976
2125
},
@@ -35,6 +39,12 @@
3539
],
3640
"workers_dev": false,
3741
"preview_urls": false,
42+
"analytics_engine_datasets": [
43+
{
44+
"binding": "MCP_METRICS",
45+
"dataset": "mcp-metrics-dev"
46+
}
47+
],
3848
"env": {
3949
"staging": {
4050
"name": "mcp-cloudflare-casb-staging",
@@ -53,6 +63,12 @@
5363
"binding": "OAUTH_KV",
5464
"id": "18e839155d00407095d793dcf7e78f25"
5565
}
66+
],
67+
"analytics_engine_datasets": [
68+
{
69+
"binding": "MCP_METRICS",
70+
"dataset": "mcp-metrics-staging"
71+
}
5672
]
5773
},
5874
"production": {
@@ -72,6 +88,12 @@
7288
"binding": "OAUTH_KV",
7389
"id": "f9782295993747df90c29c45ca89edb1"
7490
}
91+
],
92+
"analytics_engine_datasets": [
93+
{
94+
"binding": "MCP_METRICS",
95+
"dataset": "mcp-metrics-production"
96+
}
7597
]
7698
}
7799
}

apps/docs-autorag/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"check:lint": "run-eslint-workers",
77
"check:types": "run-tsc",
8-
"deploy": "wrangler deploy",
8+
"deploy": "run-wrangler-deploy",
99
"dev": "wrangler dev",
1010
"start": "wrangler dev",
1111
"cf-typegen": "wrangler types",
@@ -16,6 +16,7 @@
1616
"@hono/zod-validator": "0.4.3",
1717
"@modelcontextprotocol/sdk": "1.9.0",
1818
"@repo/mcp-common": "workspace:*",
19+
"@repo/mcp-observability": "workspace:*",
1920
"agents": "0.0.62",
2021
"cloudflare": "4.2.0",
2122
"hono": "4.7.6",
@@ -25,6 +26,7 @@
2526
"devDependencies": {
2627
"@cloudflare/vitest-pool-workers": "0.8.14",
2728
"@cloudflare/workers-types": "4.20250410.0",
29+
"@types/node": "^22.14.1",
2830
"prettier": "3.5.3",
2931
"typescript": "5.5.4",
3032
"vitest": "3.0.9",

apps/docs-autorag/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
21
import { McpAgent } from 'agents/mcp'
2+
import { env } from 'cloudflare:workers'
3+
4+
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
35

46
import { registerDocsTools } from './tools/docs'
57

@@ -9,9 +11,9 @@ export type Props = never
911
export type State = never
1012

1113
export class CloudflareDocumentationMCP extends McpAgent<Env, State, Props> {
12-
server = new McpServer({
13-
name: 'Remote MCP Server with Cloudflare Documentation',
14-
version: '1.0.0',
14+
server = new CloudflareMCPServer(undefined, env.MCP_METRICS, {
15+
name: env.MCP_SERVER_NAME,
16+
version: env.MCP_SERVER_VERSION,
1517
})
1618

1719
constructor(

apps/docs-autorag/worker-configuration.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types` (hash: f47f9f62d3a1ddb9823a379fdafce5ce)
3-
// Runtime types generated with workerd@1.20250417.0 2025-03-10 nodejs_compat
2+
// Generated by Wrangler by running `wrangler types` (hash: 23bfeb1ecdb06845b72c16f50728901d)
3+
// Runtime types generated with workerd@1.20250422.0 2025-03-10 nodejs_compat
44
declare namespace Cloudflare {
55
interface Env {
66
ENVIRONMENT: "development" | "staging" | "production";
77
AUTORAG_NAME: "cloudflare-docs-autorag";
8+
MCP_SERVER_NAME: "PLACEHOLDER";
9+
MCP_SERVER_VERSION: "PLACEHOLDER";
810
MCP_OBJECT: DurableObjectNamespace<import("./src/index").CloudflareDocumentationMCP>;
11+
MCP_METRICS: AnalyticsEngineDataset;
912
AI: Ai;
1013
}
1114
}

apps/docs-autorag/wrangler.jsonc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@
3030
},
3131
"vars": {
3232
"ENVIRONMENT": "development",
33-
"AUTORAG_NAME": "cloudflare-docs-autorag"
33+
"AUTORAG_NAME": "cloudflare-docs-autorag",
34+
"MCP_SERVER_NAME": "PLACEHOLDER",
35+
"MCP_SERVER_VERSION": "PLACEHOLDER"
3436
},
3537
"dev": {
3638
"port": 8976
3739
},
3840
"workers_dev": false,
3941
"preview_urls": false,
42+
"analytics_engine_datasets": [
43+
{
44+
"binding": "MCP_METRICS",
45+
"dataset": "mcp-metrics-dev"
46+
}
47+
],
4048
"env": {
4149
"staging": {
4250
"name": "mcp-cloudflare-docs-autorag-staging",
@@ -54,10 +62,15 @@
5462
"ENVIRONMENT": "staging",
5563
"AUTORAG_NAME": "cloudflare-docs-autorag"
5664
},
57-
5865
"ai": {
5966
"binding": "AI"
60-
}
67+
},
68+
"analytics_engine_datasets": [
69+
{
70+
"binding": "MCP_METRICS",
71+
"dataset": "mcp-metrics-staging"
72+
}
73+
]
6174
},
6275
"production": {
6376
"name": "mcp-cloudflare-docs-autorag-production",
@@ -77,7 +90,13 @@
7790
},
7891
"ai": {
7992
"binding": "AI"
80-
}
93+
},
94+
"analytics_engine_datasets": [
95+
{
96+
"binding": "MCP_METRICS",
97+
"dataset": "mcp-metrics-production"
98+
}
99+
]
81100
}
82101
}
83102
}

apps/sandbox-container/evals/exec.eval.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ eachModel('$modelName', ({ model }) => {
5252
},
5353
scorers: [checkFactuality],
5454
threshold: 1,
55+
timeout: 60000,
5556
})
5657
})

apps/sandbox-container/evals/files.eval.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ eachModel('$modelName', ({ model }) => {
5151
},
5252
scorers: [checkFactuality],
5353
threshold: 1,
54+
timeout: 60000,
5455
})
5556

5657
describeEval('Runs container file delete', {
@@ -102,5 +103,6 @@ eachModel('$modelName', ({ model }) => {
102103
},
103104
scorers: [checkFactuality],
104105
threshold: 1,
106+
timeout: 60000,
105107
})
106108
})

0 commit comments

Comments
 (0)