Skip to content

fix: PNPM Lockfile with CASB included #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/cloudflare-one-casb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types",
"types": "wrangler types --include-env=false",
"test": "vitest run"
},
"dependencies": {
"@cloudflare/workers-oauth-provider": "0.0.2",
"@cloudflare/workers-oauth-provider": "0.0.3",
"@hono/zod-validator": "0.4.3",
"@modelcontextprotocol/sdk": "1.9.0",
"@modelcontextprotocol/sdk": "1.10.2",
"@repo/mcp-common": "workspace:*",
"agents": "0.0.49",
"agents": "0.0.67",
"cloudflare": "4.2.0",
"hono": "4.7.6",
"zod": "3.24.2"
Expand Down
15 changes: 15 additions & 0 deletions apps/cloudflare-one-casb/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { CASBMCP, UserDetails } from './index'

export interface Env {
ENVIRONMENT: 'development' | 'staging' | 'production'
MCP_SERVER_NAME: string
MCP_SERVER_VERSION: string
MCP_OBJECT: DurableObjectNamespace<CASBMCP>
MCP_METRICS: AnalyticsEngineDataset
AI: Ai

CLOUDFLARE_CLIENT_ID: string
CLOUDFLARE_CLIENT_SECRET: string

USER_DETAILS: DurableObjectNamespace<UserDetails>
}
38 changes: 24 additions & 14 deletions apps/cloudflare-one-casb/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import OAuthProvider from '@cloudflare/workers-oauth-provider'
import { McpAgent } from 'agents/mcp'
import { env } from 'cloudflare:workers'

import {
createAuthHandlers,
handleTokenExchangeCallback,
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details'
import { getEnv } from '@repo/mcp-common/src/env'
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
import { registerAccountTools } from '@repo/mcp-common/src/tools/account'

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

import type { AccountSchema, UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
import type { CloudflareMcpAgent } from '@repo/mcp-common/src/types/cloudflare-mcp-agent'
import type { Env } from './context'

export { UserDetails }

const env = getEnv<Env>()

const metrics = new MetricsTracker(env.MCP_METRICS, {
name: env.MCP_SERVER_NAME,
Expand Down Expand Up @@ -46,32 +51,37 @@ export class CASBMCP extends McpAgent<Env, State, Props> {
}

async init() {
this.server = new CloudflareMCPServer(this.props.user.id, this.env.MCP_METRICS, {
name: this.env.MCP_SERVER_NAME,
version: this.env.MCP_SERVER_VERSION,
this.server = new CloudflareMCPServer({
userId: this.props.user.id,
wae: this.env.MCP_METRICS,
serverInfo: {
name: this.env.MCP_SERVER_NAME,
version: this.env.MCP_SERVER_VERSION,
},
})

registerAccountTools(this)
registerIntegrationsTools(this)
}

getActiveAccountId() {
async getActiveAccountId() {
try {
return this.state.activeAccountId ?? null
// Get UserDetails Durable Object based off the userId and retrieve the activeAccountId from it
// we do this so we can persist activeAccountId across sessions
const userDetails = getUserDetails(env, this.props.user.id)
return await userDetails.getActiveAccountId()
} catch (e) {
console.error('getActiveAccountId failured: ', e)
this.server.recordError(e)
return null
}
}

setActiveAccountId(accountId: string) {
async setActiveAccountId(accountId: string) {
try {
this.setState({
...this.state,
activeAccountId: accountId,
})
const userDetails = getUserDetails(env, this.props.user.id)
await userDetails.setActiveAccountId(accountId)
} catch (e) {
return null
this.server.recordError(e)
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions apps/cloudflare-one-casb/src/tools/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
assetCategoryVendorParam,
} from '@repo/mcp-common/src/schemas/cf1-integrations'

import type { McpAgentWithAccount } from '@repo/mcp-common/src/api/account'
import type { ToolDefinition } from '@repo/mcp-common/src/types/tools'
import type { CASBMCP } from '../index'

Expand Down Expand Up @@ -244,11 +243,6 @@ const toolDefinitions: Array<ToolDefinition<any>> = [
*/
export function registerIntegrationsTools(agent: CASBMCP) {
toolDefinitions.forEach(({ name, description, params, handler }) => {
agent.server.tool(
name,
description,
params,
withAccountCheck(agent as unknown as McpAgentWithAccount, handler)
)
agent.server.tool(name, description, params, withAccountCheck(agent, handler))
})
}
2 changes: 2 additions & 0 deletions apps/cloudflare-one-casb/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'

import type { Env } from './src/context'

export interface TestEnv extends Env {
CLOUDFLARE_MOCK_ACCOUNT_ID: string
CLOUDFLARE_MOCK_API_TOKEN: string
Expand Down
15 changes: 0 additions & 15 deletions apps/cloudflare-one-casb/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
// Generated by Wrangler by running `wrangler types` (hash: 085ce38c6421603ed1a73fa9678ae0a7)
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
declare namespace Cloudflare {
interface Env {
OAUTH_KV: KVNamespace;
CLOUDFLARE_CLIENT_ID: string;
CLOUDFLARE_CLIENT_SECRET: string;
MCP_OBJECT: DurableObjectNamespace<import("./src/index").CASBMCP>;

MCP_SERVER_NAME: "PLACEHOLDER";
MCP_SERVER_VERSION: "PLACEHOLDER";
MCP_METRICS: AnalyticsEngineDataset;
}
}
interface Env extends Cloudflare.Env {}

// Begin runtime types
/*! *****************************************************************************
Copyright (c) Cloudflare. All rights reserved.
Expand Down
5 changes: 4 additions & 1 deletion apps/cloudflare-one-casb/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
},
"vars": {
"MCP_SERVER_NAME": "PLACEHOLDER",
"MCP_SERVER_VERSION": "PLACEHOLDER"
"MCP_SERVER_VERSION": "PLACEHOLDER",
"CLOUDFLARE_CLIENT_ID": "<PLACEHOLDER>",
"CLOUDFLARE_CLIENT_SECRET": "<PLACEHOLDER>"
},

"dev": {
"port": 8976
},
Expand Down
Loading