mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
fix(core): mark an MCP server with an invalid URL as failed (#61149)
This commit is contained in:
committed by
GitHub
Unverified
parent
271f5ef9bc
commit
0d73f08f28
@@ -298,8 +298,6 @@ export const connect = Effect.fnUntraced(function* (
|
||||
})
|
||||
return yield* initialize(transport)
|
||||
}
|
||||
if (!URL.canParse(config.url))
|
||||
return yield* new ConnectError({ server, message: `Invalid MCP URL for "${server}"` })
|
||||
const { McpOAuth } = yield* Effect.promise(() => import("./oauth.js"))
|
||||
const fetch = yield* McpOAuth.loggedFetch({ server, directory })
|
||||
// Servers that bundle their own Code Mode (Cloudflare and others) expose raw tools when asked
|
||||
|
||||
@@ -146,6 +146,9 @@ export function make(input: Input): Connection {
|
||||
const start: Effect.Effect<void> = Effect.suspend(() =>
|
||||
Effect.gen(function* () {
|
||||
yield* input.events.connecting
|
||||
// Checked before the OAuth provider is built, which parses the URL too.
|
||||
if (input.config.type === "remote" && !URL.canParse(input.config.url))
|
||||
return yield* input.events.failed({ status: "failed", error: `Invalid MCP server URL: ${input.config.url}` })
|
||||
const scope = yield* Scope.fork(input.scope)
|
||||
state.scope = scope
|
||||
const authProvider = yield* input.authProvider
|
||||
|
||||
@@ -395,6 +395,7 @@ function resourceMcpLayer(
|
||||
}),
|
||||
Layer.mock(Integration.Service, {
|
||||
revision: () => 0,
|
||||
transform: () => Effect.succeed({ dispose: Effect.void }),
|
||||
connection: {
|
||||
active: unusedIntegration,
|
||||
resolve: unusedIntegration,
|
||||
@@ -417,7 +418,7 @@ function resourceMcpLayer(
|
||||
cancel: unusedIntegration,
|
||||
},
|
||||
}),
|
||||
Layer.mock(Credential.Service, {}),
|
||||
Layer.mock(Credential.Service, { list: () => Effect.succeed([]) }),
|
||||
overrides?.environment ?? hostEnvironmentLayer,
|
||||
),
|
||||
),
|
||||
@@ -1828,6 +1829,30 @@ test("adds, disconnects, and reconnects MCP servers at runtime", async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test("marks a remote MCP server with an invalid URL as failed", async () => {
|
||||
await Effect.runPromise(
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const server = yield* resourceServer({ modern: true, resources: false })
|
||||
const config = { type: "remote", url: server.url, oauth: false, protocol: "2026-07-28" } as const
|
||||
yield* Effect.gen(function* () {
|
||||
const service = yield* Mcp.Service
|
||||
const status = (name: string) =>
|
||||
service.servers().pipe(Effect.map((servers) => servers.find((server) => server.name === name)?.status))
|
||||
expect(yield* settled(service)).toEqual({ status: "connected" })
|
||||
|
||||
yield* service.add("broken", new ConfigMCP.Remote({ type: "remote", url: "not a url" }))
|
||||
expect(yield* status("broken")).toEqual({ status: "failed", error: "Invalid MCP server URL: not a url" })
|
||||
expect(yield* status("resources")).toEqual({ status: "connected" })
|
||||
|
||||
yield* service.add("broken", new ConfigMCP.Remote(config))
|
||||
expect(yield* status("broken")).toEqual({ status: "connected" })
|
||||
}).pipe(Effect.provide(resourceMcpLayer(new ConfigMCP.Remote(config))))
|
||||
}),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
testEffect(Layer.empty).live(
|
||||
"merges MCP defaults into the winning configured server without changing runtime overrides",
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user