Skip to content
Open
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
4 changes: 3 additions & 1 deletion packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ export namespace MCP {
return dynamicTool({
description: mcpTool.description ?? "",
inputSchema: jsonSchema(schema),
execute: async (args: unknown) => {
execute: async (args: unknown, opts?) => {
const meta = (opts as any)?._meta as Record<string, unknown> | undefined
return client.callTool(
{
name: mcpTool.name,
arguments: (args || {}) as Record<string, unknown>,
...(meta ? { _meta: meta } : {}),
},
CallToolResultSchema,
{
Expand Down
5 changes: 3 additions & 2 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,15 @@ NOTE: At any point in time through this workflow you should feel free to ask the
Effect.runPromise(
Effect.gen(function* () {
const ctx = context(args, opts)
const hookOutput: { args: unknown; _meta?: Record<string, unknown> } = { args }
yield* plugin.trigger(
"tool.execute.before",
{ tool: key, sessionID: ctx.sessionID, callID: opts.toolCallId },
{ args },
hookOutput,
)
yield* Effect.promise(() => ctx.ask({ permission: key, metadata: {}, patterns: ["*"], always: ["*"] }))
const result: Awaited<ReturnType<NonNullable<typeof execute>>> = yield* Effect.promise(() =>
execute(args, opts),
execute(hookOutput.args, { ...opts, _meta: hookOutput._meta } as typeof opts),
)
yield* plugin.trigger(
"tool.execute.after",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export interface Hooks {
) => Promise<void>
"tool.execute.before"?: (
input: { tool: string; sessionID: string; callID: string },
output: { args: any },
output: { args: any; _meta?: Record<string, unknown> },
) => Promise<void>
"shell.env"?: (
input: { cwd: string; sessionID?: string; callID?: string },
Expand Down
Loading