Skip to content
Merged
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
6 changes: 6 additions & 0 deletions packages/core/src/mcp/client/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import {
registerMcpClientRequestHandlers,
unregisterMcpClientRequestHandlers,
} from './roots'
import {
registerMcpSamplingHandler,
unregisterMcpSamplingHandler,
} from './sampling'
import type { WrappedClient } from './types'

type GlobalWithWebSocket = { WebSocket?: unknown }
Expand Down Expand Up @@ -101,6 +105,7 @@ export function createMcpClient(
createMcpClientSdkOptions(name),
)
registerMcpClientRequestHandlers(client)
registerMcpSamplingHandler(client)
client.setNotificationHandler(
LoggingMessageNotificationSchema,
notification => {
Expand All @@ -121,6 +126,7 @@ export function createMcpClient(

export async function closeMcpClient(client: Client): Promise<void> {
unregisterMcpClientRequestHandlers(client)
unregisterMcpSamplingHandler(client)
try {
await client.close()
} catch {}
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/mcp/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ export {
type McpLogMessageEvent,
type McpLoggingLevel,
} from './logging'
export {
__resetMcpSamplingForTests,
__setMcpSamplingEnabledForTests,
isMcpSamplingEnabled,
setMcpSamplingEnabled,
} from './sampling'
14 changes: 11 additions & 3 deletions packages/core/src/mcp/client/roots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { checkHasTrustDialogAccepted } from '#core/utils/config'
import { logMCPError } from '#core/utils/log'
import { getCwd, subscribeCwdChanged } from '#core/utils/state'
import { isMcpSamplingEnabled } from './sampling'

let exposeRootsOverrideForTests: boolean | null = null
const rootsClients = new Set<Client>()
Expand Down Expand Up @@ -43,10 +44,17 @@ export function shouldExposeMcpRoots(): boolean {
}

export function getMcpClientCapabilities(): ClientCapabilities {
if (!shouldExposeMcpRoots()) return {}
return {
roots: { listChanged: true },
const capabilities: ClientCapabilities = {}

if (shouldExposeMcpRoots()) {
capabilities.roots = { listChanged: true }
}

if (isMcpSamplingEnabled()) {
capabilities.sampling = {}
}

return capabilities
}

function ensureCwdChangedSubscription(): void {
Expand Down
Loading
Loading