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
10import postgres from "postgres";10import postgres from "postgres";
11 11
12import { createExecutorMcpServer } from "@executor/host-mcp";12import { createExecutorMcpServer } from "@executor/host-mcp";
13import { createExecutionEngine } from "@executor/execution";
13import { makeDynamicWorkerExecutor } from "@executor/runtime-dynamic-worker";14import { makeDynamicWorkerExecutor } from "@executor/runtime-dynamic-worker";
14import type { DrizzleDb } from "@executor/storage-postgres";15import type { DrizzleDb } from "@executor/storage-postgres";
15import * as sharedSchema from "@executor/storage-postgres/schema";16import * as sharedSchema from "@executor/storage-postgres/schema";
16 17
18import { makeTrackExecutionUsage } from "./api/autumn";
19import { withExecutionUsageTracking } from "./api/execution-usage";
17import { UserStoreService } from "./auth/context";20import { UserStoreService } from "./auth/context";
18import { resolveOrganization } from "./auth/resolve-organization";21import { resolveOrganization } from "./auth/resolve-organization";
19import { WorkOSAuth } from "./auth/workos";22import { WorkOSAuth } from "./auth/workos";
20import { server } from "./env";23import { server } from "./env";
24import { AutumnService } from "./services/autumn";
21import { createOrgExecutor } from "./services/executor";25import { createOrgExecutor } from "./services/executor";
22import { DbService } from "./services/db";26import { DbService } from "./services/db";
23import * as cloudSchema from "./services/schema";27import * as cloudSchema from "./services/schema";
@@ -107,7 +111,12 @@ export class McpSessionDO extends DurableObject { · 83 unmodified lines
107 111
108 const DbLive = Layer.succeed(DbService, this.dbHandle.db);112 const DbLive = Layer.succeed(DbService, this.dbHandle.db);
109 const UserStoreLive = UserStoreService.Live.pipe(Layer.provide(DbLive));113 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 );
111 120
112 const program = Effect.gen(function* () {121 const program = Effect.gen(function* () {
113 const org = yield* resolveOrganization(token.organizationId);122 const org = yield* resolveOrganization(token.organizationId);
@@ -116,7 +125,13 @@ export class McpSessionDO extends DurableObject { · 2 unmodified lines
116 125
117 const executor = yield* createOrgExecutor(org.id, org.name);126 const executor = yield* createOrgExecutor(org.id, org.name);
118 const codeExecutor = makeDynamicWorkerExecutor({ loader: env.LOADER });127 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 }));
120 }).pipe(Effect.provide(Services));135 }).pipe(Effect.provide(Services));
121 136
122 this.mcpServer = await Effect.runPromise(program);137 this.mcpServer = await Effect.runPromise(program);
bun.lock+1−0
@@ -324,6 +324,7 @@ · 323 unmodified lines
324 "name": "@executor/codemode-core",324 "name": "@executor/codemode-core",
325 "version": "1.4.3",325 "version": "1.4.3",
326 "dependencies": {326 "dependencies": {
327 "@babel/parser": "^7.29.2",
327 "@standard-schema/spec": "^1.0.0",328 "@standard-schema/spec": "^1.0.0",
328 "ajv": "^8.17.1",329 "ajv": "^8.17.1",
329 "ajv-formats": "^3.0.1",330 "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