feat(core): expose mcp prompts as commands
This commit is contained in:
parent
4ef19f2e6a
commit
1245420e53
5 changed files with 43 additions and 0 deletions
33
packages/core/src/plugin/mcp-command.ts
Normal file
33
packages/core/src/plugin/mcp-command.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
export * as McpCommandPlugin from "./mcp-command"
|
||||
|
||||
import { McpEvent } from "@opencode-ai/schema/mcp-event"
|
||||
import { Effect, Stream } from "effect"
|
||||
import { EventV2 } from "../event"
|
||||
import { MCP } from "../mcp"
|
||||
import { define } from "./internal"
|
||||
|
||||
export const Plugin = define({
|
||||
id: "mcp-command",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const mcp = yield* MCP.Service
|
||||
const events = yield* EventV2.Service
|
||||
yield* ctx.command.transform(
|
||||
Effect.fn(function* (draft) {
|
||||
for (const prompt of yield* mcp.prompts()) {
|
||||
draft.update(commandName(prompt), (command) => {
|
||||
command.template = ""
|
||||
command.description = prompt.description
|
||||
command.source = "mcp"
|
||||
})
|
||||
}
|
||||
}),
|
||||
)
|
||||
yield* events
|
||||
.subscribe(McpEvent.PromptsChanged)
|
||||
.pipe(Stream.runForEach(() => ctx.command.reload()), Effect.forkScoped({ startImmediately: true }))
|
||||
}),
|
||||
})
|
||||
|
||||
const commandName = (prompt: MCP.Prompt) => `${sanitize(prompt.server)}:${sanitize(prompt.name)}`
|
||||
|
||||
const sanitize = (value: string) => value.replace(/[^a-zA-Z0-9_-]/g, "_")
|
||||
Loading…
Add table
Add a link
Reference in a new issue