Skip to content
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
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"generate:expo-schema": "node scripts/fetch-expo-schema.ts"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.3.284",
"@anthropic-ai/claude-agent-sdk": "^0.3.316",
"@cursor/sdk": "1.2.0",
"@effect/platform-node": "catalog:",
"@effect/platform-node-shared": "catalog:",
Expand Down
42 changes: 38 additions & 4 deletions apps/server/src/mcpApps/McpAppRequests.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ProviderDriverKind,
ProviderSessionId,
ProviderThreadId,
ThreadId,
Expand All @@ -14,7 +15,7 @@ import * as Layer from "effect/Layer";
import * as Option from "effect/Option";

import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import * as ProviderSessionManager from "../orchestration-v2/ProviderSessionManager.ts";
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
import * as McpAppModelContext from "./McpAppModelContext.ts";
Expand Down Expand Up @@ -137,8 +138,12 @@ describe("McpAppRequests", () => {
const mcpApps: ProviderAdapter.ProviderAdapterV2McpApps = {
listTools: () =>
Effect.succeed([
{ name: "refresh", annotations: { readOnlyHint: true } },
{ name: "model_only", _meta: { ui: { visibility: ["model"] } } },
{ name: "refresh", inputSchema: { type: "object" }, annotations: { readOnlyHint: true } },
{
name: "model_only",
inputSchema: { type: "object" },
_meta: { ui: { visibility: ["model"] } },
},
]),
callTool: (input) =>
Effect.sync(() => {
Expand All @@ -162,7 +167,11 @@ describe("McpAppRequests", () => {
assert.deepEqual(yield* requests.toolInfo({ threadId, itemId, name: "refresh" }), {
callable: true,
readOnly: true,
tool: { name: "refresh", annotations: { readOnlyHint: true } },
tool: {
name: "refresh",
inputSchema: { type: "object" },
annotations: { readOnlyHint: true },
},
});
}).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))),
);
Expand All @@ -181,6 +190,31 @@ describe("McpAppRequests", () => {
}).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))),
);

it.effect("reports a provider whose process has stopped as a stopped session", () =>
Effect.gen(function* () {
const requests = yield* McpAppRequests.McpAppRequests;
assert.equal(
yield* reason(requests.readResource({ threadId, itemId, uri: "ui://weather/app.html" })),
"session-stopped",
);
}).pipe(
Effect.provide(
makeLayer({
item: appItem({ t3McpApp: app }),
mcpApps: {
...mcpApps,
readResource: () =>
Effect.fail(
new ProviderAdapter.ProviderAdapterSessionStoppedError({
driver: ProviderDriverKind.make("claudeAgent"),
}),
),
},
}),
),
),
);

it.effect("keeps each app's latest model context, without a live session", () =>
Effect.gen(function* () {
const requests = yield* McpAppRequests.McpAppRequests;
Expand Down
12 changes: 9 additions & 3 deletions apps/server/src/mcpApps/McpAppRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const make = Effect.gen(function* () {

const fail = (threadId: ThreadId, reason: McpAppRequestError["reason"], cause?: unknown) =>
new McpAppRequestError({ threadId, reason, ...(cause === undefined ? {} : { cause }) });
const adapterFailure = (threadId: ThreadId) => (cause: ProviderAdapter.ProviderAdapterV2Error) =>
fail(
threadId,
cause._tag === "ProviderAdapterSessionStoppedError" ? "session-stopped" : "request-failed",
cause,
);

const resolveApp = Effect.fn("McpAppRequests.resolveApp")(function* (input: {
readonly threadId: ThreadId;
Expand Down Expand Up @@ -112,7 +118,7 @@ const make = Effect.gen(function* () {
) {
const tools = yield* resolved.mcpApps
.listTools({ providerThread: resolved.providerThread, server: resolved.app.server })
.pipe(Effect.mapError((cause) => fail(threadId, "request-failed", cause)));
.pipe(Effect.mapError(adapterFailure(threadId)));
return tools.find((tool) => tool.name === name);
});

Expand Down Expand Up @@ -142,7 +148,7 @@ const make = Effect.gen(function* () {
tool: input.name,
arguments: input.arguments,
})
.pipe(Effect.mapError((cause) => fail(input.threadId, "request-failed", cause)));
.pipe(Effect.mapError(adapterFailure(input.threadId)));
});

const readResource = Effect.fn("McpAppRequests.readResource")(function* (
Expand All @@ -155,7 +161,7 @@ const make = Effect.gen(function* () {
server: resolved.app.server,
uri: input.uri,
})
.pipe(Effect.mapError((cause) => fail(input.threadId, "request-failed", cause)));
.pipe(Effect.mapError(adapterFailure(input.threadId)));
});

const descendsFrom = Effect.fn("McpAppRequests.descendsFrom")(function* (
Expand Down
Loading
Loading