refactor(opencode): align mcp service and tests with native tool entries
This commit is contained in:
parent
da6626b4c1
commit
3641fec04f
4 changed files with 7 additions and 10 deletions
|
|
@ -210,6 +210,10 @@ const layer = Layer.effect(
|
|||
|
||||
type Transport = StdioClientTransport | StreamableHTTPClientTransport | SSEClientTransport
|
||||
|
||||
/**
|
||||
* Connect a client via the given transport with resource safety:
|
||||
* on failure the transport is closed; on success the caller owns it.
|
||||
*/
|
||||
const connectTransport = Effect.fn("MCP.connectTransport")(function* (transport: Transport, timeout: number) {
|
||||
const directory = yield* InstanceState.directory
|
||||
return yield* Effect.acquireUseRelease(
|
||||
|
|
|
|||
|
|
@ -117,7 +117,6 @@ function makeMcp(instructions: MCP.ServerInstructions[] = []) {
|
|||
clients: () => Effect.succeed({}),
|
||||
instructions: () => Effect.succeed(instructions),
|
||||
tools: () => Effect.succeed({}),
|
||||
defs: () => Effect.succeed({}),
|
||||
prompts: () => Effect.succeed({}),
|
||||
resources: () => Effect.succeed({}),
|
||||
resourceTemplates: () => Effect.succeed({}),
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ const mcp = Layer.succeed(
|
|||
clients: () => Effect.succeed({}),
|
||||
instructions: () => Effect.succeed([]),
|
||||
tools: () => Effect.succeed({}),
|
||||
defs: () => Effect.succeed({}),
|
||||
prompts: () => Effect.succeed({}),
|
||||
resources: () => Effect.succeed({}),
|
||||
resourceTemplates: () => Effect.succeed({}),
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import {
|
|||
ListToolsRequestSchema,
|
||||
type Tool as MCPToolDef,
|
||||
} from "@modelcontextprotocol/sdk/types.js"
|
||||
import type { Tool as AITool } from "ai"
|
||||
import { Effect, Layer } from "effect"
|
||||
|
||||
const PNG =
|
||||
|
|
@ -135,12 +134,9 @@ async function buildTool() {
|
|||
await client.connect()
|
||||
|
||||
const listed = (await client.listTools()).tools as MCPToolDef[]
|
||||
const mcpTools: Record<string, AITool> = {}
|
||||
const mcpDefs: Record<string, MCPToolDef> = {}
|
||||
const mcpTools: Record<string, MCP.McpTool> = {}
|
||||
for (const def of listed) {
|
||||
const key = McpCatalog.toolName(SERVER, def.name)
|
||||
mcpDefs[key] = def
|
||||
mcpTools[key] = McpCatalog.convertTool(def, client as unknown as Client)
|
||||
mcpTools[McpCatalog.toolName(SERVER, def.name)] = { def, client: client as unknown as Client }
|
||||
}
|
||||
|
||||
const layer = Layer.mergeAll(
|
||||
|
|
@ -155,13 +151,12 @@ async function buildTool() {
|
|||
Layer.mock(Session.Service, { get: () => Effect.succeed({ permission: [] } as any) }),
|
||||
Layer.mock(MCP.Service, {
|
||||
tools: () => Effect.succeed(mcpTools),
|
||||
defs: () => Effect.succeed(mcpDefs),
|
||||
clients: () => Effect.succeed({ [SERVER]: {} as any }),
|
||||
}),
|
||||
)
|
||||
return {
|
||||
tool: await Effect.runPromise(CodeModeTool.pipe(Effect.flatMap(Tool.init), Effect.provide(layer))),
|
||||
description: describeCatalog(mcpTools, mcpDefs, [SERVER]),
|
||||
description: describeCatalog(mcpTools, [SERVER]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue