Skip to content
Closed
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
21 changes: 21 additions & 0 deletions packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
import {
CallToolResultSchema,
LoggingMessageNotificationSchema,
type Tool as MCPToolDef,
ToolListChangedNotificationSchema,
} from "@modelcontextprotocol/sdk/types.js"
Expand Down Expand Up @@ -60,6 +61,15 @@ export namespace MCP {
}),
)

export const MessageReceived = BusEvent.define(
"mcp.message.received",
z.object({
server: z.string(),
level: z.string(),
data: z.string(),
}),
)

export const Failed = NamedError.create(
"MCPFailed",
z.object({
Expand Down Expand Up @@ -475,6 +485,17 @@ export namespace MCP {
s.defs[name] = listed
await Effect.runPromise(bus.publish(ToolsChanged, { server: name }).pipe(Effect.ignore))
})

client.setNotificationHandler(LoggingMessageNotificationSchema, async (notification) => {
const level = notification.params.level ?? "info"
const data = typeof notification.params.data === "string"
? notification.params.data
: JSON.stringify(notification.params.data)
log.info("message notification received", { server: name, level, data: data.slice(0, 200) })
await Effect.runPromise(
bus.publish(MessageReceived, { server: name, level, data }).pipe(Effect.ignore),
)
})
}

const cache = yield* InstanceState.make<State>(
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/session/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const log = Log.create({ service: "instruction" })

const FILES = [
"AGENTS.md",
"CLAUDE.md",
...(Flag.OPENCODE_DISABLE_CLAUDE_CODE_PROMPT ? [] : ["CLAUDE.md"]),
"CONTEXT.md", // deprecated
]

Expand Down
Loading