fix(httpapi): return mcp server not found errors (#28817)

This commit is contained in:
Shoubhit Dash
2026-05-22 17:46:30 +05:30
committed by GitHub
parent 51da3483a9
commit 0beb4de3e8
8 changed files with 158 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
import { expect, mock, beforeEach } from "bun:test"
import { Effect, Exit } from "effect"
import { Cause, Effect, Exit } from "effect"
import type { MCP as MCPNS } from "../../src/mcp/index"
import { testEffect } from "../lib/effect"
@@ -635,12 +635,15 @@ it.instance(
// ========================================================================
it.instance(
"connect() on nonexistent server does not throw",
"connect() on nonexistent server fails with NotFoundError",
() =>
MCP.Service.use((mcp: MCPNS.Interface) =>
Effect.gen(function* () {
// Should not throw
yield* mcp.connect("nonexistent")
const exit = yield* mcp.connect("nonexistent").pipe(Effect.exit)
expect(Exit.isFailure(exit)).toBe(true)
if (Exit.isFailure(exit)) {
expect(Cause.squash(exit.cause)).toMatchObject({ _tag: "MCP.NotFoundError", name: "nonexistent" })
}
const status = yield* mcp.status()
expect(status["nonexistent"]).toBeUndefined()
}),
@@ -653,12 +656,15 @@ it.instance(
// ========================================================================
it.instance(
"disconnect() on nonexistent server does not throw",
"disconnect() on nonexistent server fails with NotFoundError",
() =>
MCP.Service.use((mcp: MCPNS.Interface) =>
Effect.gen(function* () {
yield* mcp.disconnect("nonexistent")
// Should complete without error
const exit = yield* mcp.disconnect("nonexistent").pipe(Effect.exit)
expect(Exit.isFailure(exit)).toBe(true)
if (Exit.isFailure(exit)) {
expect(Cause.squash(exit.cause)).toMatchObject({ _tag: "MCP.NotFoundError", name: "nonexistent" })
}
}),
),
{ config: { mcp: {} } },