History

Track MCP tool executions in Autumn billing (#237)

* Track MCP tool executions in Autumn billing MCP tool calls bypassed the execution-usage tracking wrapper because the session DO built the engine implicitly inside createExecutorMcpServer. Build the engine in the DO, wrap it with withExecutionUsageTracking, and pass it through so executions increment the Autumn `executions` feature. * fix lockfile

Rhys Sullivan committed 7 months ago

Commit c9aa58b1 parent 44bfe3e2 files · +18 −2Browse files

Unified · Split

2 files
  1. apps/cloud/src/mcp-session.ts +17 −2
  2. bun.lock +1 −0
apps/cloud/src/mcp-session.ts+17−2
@@ -10,14 +10,18 @@ import { drizzle } from "drizzle-orm/postgres-js"; · 9 unmodified lines
1010 import postgres from "postgres";
1111
1212 import { createExecutorMcpServer } from "@executor/host-mcp";
13+import { createExecutionEngine } from "@executor/execution";
1314 import { makeDynamicWorkerExecutor } from "@executor/runtime-dynamic-worker";
1415 import type { DrizzleDb } from "@executor/storage-postgres";
1516 import * as sharedSchema from "@executor/storage-postgres/schema";
1617
18+import { makeTrackExecutionUsage } from "./api/autumn";
19+import { withExecutionUsageTracking } from "./api/execution-usage";
1720 import { UserStoreService } from "./auth/context";
1821 import { resolveOrganization } from "./auth/resolve-organization";
1922 import { WorkOSAuth } from "./auth/workos";
2023 import { server } from "./env";
24+import { AutumnService } from "./services/autumn";
2125 import { createOrgExecutor } from "./services/executor";
2226 import { DbService } from "./services/db";
2327 import * as cloudSchema from "./services/schema";
@@ -107,7 +111,12 @@ export class McpSessionDO extends DurableObject { · 83 unmodified lines
107111
108112 const DbLive = Layer.succeed(DbService, this.dbHandle.db);
109113 const UserStoreLive = UserStoreService.Live.pipe(Layer.provide(DbLive));
110− const Services = Layer.mergeAll(DbLive, UserStoreLive, WorkOSAuth.Default);
114+ const Services = Layer.mergeAll(
115+ DbLive,
116+ UserStoreLive,
117+ WorkOSAuth.Default,
118+ AutumnService.Default,
119+ );
111120
112121 const program = Effect.gen(function* () {
113122 const org = yield* resolveOrganization(token.organizationId);
@@ -116,7 +125,13 @@ export class McpSessionDO extends DurableObject { · 2 unmodified lines
116125
117126 const executor = yield* createOrgExecutor(org.id, org.name);
118127 const codeExecutor = makeDynamicWorkerExecutor({ loader: env.LOADER });
119− return yield* Effect.promise(() => createExecutorMcpServer({ executor, codeExecutor }));
128+ const autumn = yield* AutumnService;
129+ const engine = withExecutionUsageTracking(
130+ org.id,
131+ createExecutionEngine({ executor, codeExecutor }),
132+ makeTrackExecutionUsage(autumn),
133+ );
134+ return yield* Effect.promise(() => createExecutorMcpServer({ engine }));
120135 }).pipe(Effect.provide(Services));
121136
122137 this.mcpServer = await Effect.runPromise(program);
bun.lock+1−0
@@ -324,6 +324,7 @@ · 323 unmodified lines
324324 "name": "@executor/codemode-core",
325325 "version": "1.4.3",
326326 "dependencies": {
327+ "@babel/parser": "^7.29.2",
327328 "@standard-schema/spec": "^1.0.0",
328329 "ajv": "^8.17.1",
329330 "ajv-formats": "^3.0.1",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t