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
54 changes: 27 additions & 27 deletions plugin/scripts/mcp-server.cjs

Large diffs are not rendered by default.

230 changes: 115 additions & 115 deletions plugin/scripts/server-beta-service.cjs

Large diffs are not rendered by default.

368 changes: 184 additions & 184 deletions plugin/scripts/worker-service.cjs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/servers/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
type SelectedRuntime,
type ServerBetaRuntimeContext,
} from '../services/hooks/runtime-selector.js';
import { getAdvertisedMcpToolsForRuntime } from './mcp-tool-visibility.js';

let mcpServerDirResolutionFailed = false;
const mcpServerDir = (() => {
Expand Down Expand Up @@ -905,8 +906,9 @@ const server = new Server(
);

server.setRequestHandler(ListToolsRequestSchema, async () => {
const advertisedTools = getAdvertisedMcpToolsForRuntime(tools, selectRuntime());
return {
tools: tools.map(tool => ({
tools: advertisedTools.map(tool => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema
Expand Down
29 changes: 29 additions & 0 deletions src/servers/mcp-tool-visibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { SelectedRuntime } from '../services/hooks/runtime-selector.js';
import { logger } from '../utils/logger.js';

export const SERVER_BETA_ONLY_TOOL_NAMES = [
'observation_add',
'observation_record_event',
'observation_search',
'observation_context',
'observation_generation_status',
'memory_add',
'memory_search',
'memory_context',
] as const;

const serverBetaOnlyToolNameSet = new Set<string>(SERVER_BETA_ONLY_TOOL_NAMES);

export function getAdvertisedMcpToolsForRuntime<T extends { name: string }>(
allTools: readonly T[],
runtime: SelectedRuntime
): T[] {
if (runtime === 'server-beta') {
return [...allTools];
}
logger.debug('SYSTEM', 'Filtering server-beta-only MCP tools from worker runtime advertisement', {
runtime,
hiddenToolCount: SERVER_BETA_ONLY_TOOL_NAMES.length,
});
return allTools.filter((tool) => !serverBetaOnlyToolNameSet.has(tool.name));
}
60 changes: 60 additions & 0 deletions tests/servers/mcp-runtime-tool-visibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, it, expect } from 'bun:test';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import {
getAdvertisedMcpToolsForRuntime,
SERVER_BETA_ONLY_TOOL_NAMES,
} from '../../src/servers/mcp-tool-visibility.js';

const allTools = [
{ name: 'search', description: '', inputSchema: {} },
{ name: 'timeline', description: '', inputSchema: {} },
{ name: 'get_observations', description: '', inputSchema: {} },
{ name: 'observation_add', description: '', inputSchema: {} },
{ name: 'observation_record_event', description: '', inputSchema: {} },
{ name: 'observation_search', description: '', inputSchema: {} },
{ name: 'observation_context', description: '', inputSchema: {} },
{ name: 'observation_generation_status', description: '', inputSchema: {} },
{ name: 'memory_add', description: '', inputSchema: {} },
{ name: 'memory_search', description: '', inputSchema: {} },
{ name: 'memory_context', description: '', inputSchema: {} },
{ name: 'smart_search', description: '', inputSchema: {} },
];

describe('MCP runtime-aware tool visibility', () => {
it('base-fails/head-passes: worker hides server-beta-only tool names', () => {
const workerTools = getAdvertisedMcpToolsForRuntime(allTools, 'worker');
const names = new Set(workerTools.map(tool => tool.name));

for (const toolName of SERVER_BETA_ONLY_TOOL_NAMES) {
expect(names.has(toolName)).toBe(false);
}
});

it('base-fails/head-passes: server-beta keeps server-beta-only tool names', () => {
const serverBetaTools = getAdvertisedMcpToolsForRuntime(allTools, 'server-beta');
const names = new Set(serverBetaTools.map(tool => tool.name));

for (const toolName of SERVER_BETA_ONLY_TOOL_NAMES) {
expect(names.has(toolName)).toBe(true);
}
});

it('worker runtime still advertises core MCP worker tools', () => {
const workerTools = getAdvertisedMcpToolsForRuntime(allTools, 'worker');
const names = new Set(workerTools.map(tool => tool.name));

expect(names.has('search')).toBe(true);
expect(names.has('timeline')).toBe(true);
expect(names.has('get_observations')).toBe(true);
expect(names.has('smart_search')).toBe(true);
});

it('tools/list path references the helper so discovery is runtime-aware', () => {
const mcpServerPath = join(import.meta.dir, '..', '..', 'src', 'servers', 'mcp-server.ts');
const mcpServerSrc = readFileSync(mcpServerPath, 'utf-8');

expect(mcpServerSrc).toContain('getAdvertisedMcpToolsForRuntime(tools, selectRuntime())');
expect(mcpServerSrc).not.toContain('tools.map(tool => ({');
});
});
3 changes: 2 additions & 1 deletion tests/servers/mcp-tool-schemas.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'bun:test';
import { fileURLToPath } from 'node:url';

const mcpServerPath = new URL('../../src/servers/mcp-server.ts', import.meta.url).pathname;
const mcpServerPath = fileURLToPath(new URL('../../src/servers/mcp-server.ts', import.meta.url));

describe('MCP tool inputSchema declarations', () => {
let tools: any[];
Expand Down
Loading