Skip to content

Commit ec4a47d

Browse files
authored
Forward chatbox token + workspace to Convex /stream (shared chatbox) (#1873)
1 parent 21e6509 commit ec4a47d

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

mcpjam-inspector/server/routes/web/__tests__/chat-v2.hosted.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,37 @@ describe("web routes — chat-v2 hosted mode", () => {
174174
);
175175
});
176176

177+
it("passes shared chatbox link context into the hosted model handler", async () => {
178+
const { app, token } = createWebTestApp();
179+
180+
const response = await postJson(
181+
app,
182+
"/api/web/chat-v2",
183+
{
184+
workspaceId: "workspace-1",
185+
selectedServerIds: ["server-1"],
186+
chatboxToken: "chatbox-shared-token",
187+
surface: "share_link",
188+
chatSessionId: "chat-session-shared",
189+
messages: [{ role: "user", content: "hello from guest" }],
190+
model: {
191+
id: "anthropic/claude-opus-4.6",
192+
provider: "anthropic",
193+
name: "Claude Opus 4.6",
194+
},
195+
},
196+
token,
197+
);
198+
199+
expect(response.status).toBe(200);
200+
expect(handleMCPJamFreeChatModelMock).toHaveBeenCalledWith(
201+
expect.objectContaining({
202+
chatboxToken: "chatbox-shared-token",
203+
workspaceId: "workspace-1",
204+
}),
205+
);
206+
});
207+
177208
it("forwards directVisibility for hosted direct chats", async () => {
178209
const { app, token } = createWebTestApp();
179210

mcpjam-inspector/server/routes/web/chat-v2.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ chatV2.post("/", async (c) => {
351351
temperature: resolvedTemperature,
352352
tools: allTools as ToolSet,
353353
authHeader: c.req.header("authorization"),
354+
chatboxToken,
355+
workspaceId: hostedBody.workspaceId,
354356
mcpClientManager: manager,
355357
selectedServers: selectedServerIds,
356358
requireToolApproval,

mcpjam-inspector/server/utils/mcpjam-stream-handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export interface MCPJamHandlerOptions {
7777
temperature?: number;
7878
tools: ToolSet;
7979
authHeader?: string;
80+
chatboxToken?: string;
81+
workspaceId?: string;
8082
mcpClientManager: MCPClientManager;
8183
selectedServers?: string[];
8284
requireToolApproval?: boolean;
@@ -98,6 +100,8 @@ interface StepContext {
98100
toolDefs: ToolDefinition[];
99101
tools: ToolSet;
100102
authHeader?: string;
103+
chatboxToken?: string;
104+
workspaceId?: string;
101105
modelId: string;
102106
systemPrompt: string;
103107
temperature?: number;
@@ -877,6 +881,8 @@ async function processOneStep(
877881
toolDefs,
878882
tools,
879883
authHeader,
884+
chatboxToken,
885+
workspaceId,
880886
modelId,
881887
systemPrompt,
882888
temperature,
@@ -933,6 +939,8 @@ async function processOneStep(
933939
systemPrompt,
934940
...(temperature !== undefined ? { temperature } : {}),
935941
tools: toolDefs,
942+
...(chatboxToken ? { chatboxToken } : {}),
943+
...(workspaceId ? { workspaceId } : {}),
936944
}),
937945
});
938946

@@ -1237,6 +1245,8 @@ export async function handleMCPJamFreeChatModel(
12371245
temperature,
12381246
tools,
12391247
authHeader,
1248+
chatboxToken,
1249+
workspaceId,
12401250
mcpClientManager,
12411251
selectedServers,
12421252
requireToolApproval,
@@ -1300,6 +1310,8 @@ export async function handleMCPJamFreeChatModel(
13001310
toolDefs,
13011311
tools,
13021312
authHeader,
1313+
chatboxToken,
1314+
workspaceId,
13031315
modelId,
13041316
systemPrompt,
13051317
temperature,

0 commit comments

Comments
 (0)