Skip to content
Merged
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
12 changes: 12 additions & 0 deletions packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export namespace MCP {
function registerNotificationHandlers(client: MCPClient, serverName: string) {
client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
log.info("tools list changed notification received", { server: serverName })
;(await state()).toolsCache.delete(serverName) // kilocode_change
Bus.publish(ToolsChanged, { server: serverName })
})
}
Expand Down Expand Up @@ -224,6 +225,7 @@ export namespace MCP {
return {
status,
clients,
toolsCache: new Map<string, MCPToolDef[]>(), // kilocode_change — per-server listTools cache
}
},
async (state) => {
Expand Down Expand Up @@ -302,6 +304,7 @@ export namespace MCP {

export async function add(name: string, mcp: Config.Mcp) {
const s = await state()
s.toolsCache.delete(name) // kilocode_change
const result = await create(name, mcp)
if (!result) {
const status = {
Expand Down Expand Up @@ -559,6 +562,7 @@ export namespace MCP {
}

export async function connect(name: string) {
;(await state()).toolsCache.delete(name) // kilocode_change
const cfg = await Config.get()
const config = cfg.mcp ?? {}
const mcp = config[name]
Expand Down Expand Up @@ -599,6 +603,7 @@ export namespace MCP {

export async function disconnect(name: string) {
const s = await state()
s.toolsCache.delete(name) // kilocode_change
const client = s.clients[name]
if (client) {
await client.close().catch((error) => {
Expand All @@ -623,6 +628,12 @@ export namespace MCP {

const toolsResults = await Promise.all(
connectedClients.map(async ([clientName, client]) => {
// kilocode_change start — use cached listTools when available
const cached = s.toolsCache.get(clientName)
if (cached) {
Comment thread
marius-kilocode marked this conversation as resolved.
return { clientName, client, toolsResult: { tools: cached } }
}
// kilocode_change end
const toolsResult = await client.listTools().catch((e) => {
log.error("failed to get tools", { clientName, error: e.message })
const failedStatus = {
Expand All @@ -633,6 +644,7 @@ export namespace MCP {
delete s.clients[clientName]
return undefined
})
if (toolsResult) s.toolsCache.set(clientName, toolsResult.tools) // kilocode_change
return { clientName, client, toolsResult }
}),
)
Expand Down
Loading