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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
toolToLangchain,
toolIdentifierFromToolCall,
sanitizeToolId,
createToolIdMappings,
type ToolIdMapping,
type ToolsAndMappings,
} from './tools';
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const sanitizeToolId = (toolId: string): string => {
*
* Handles id sanitization (e.g. removing dot prefixes), and potential id conflict.
*/
export const createToolIdMappings = (tools: ExecutableTool[]): ToolIdMapping => {
export const createToolIdMappings = <T extends { id: string }>(tools: T[]): ToolIdMapping => {
const toolIds = new Set<string>();
const mapping: ToolIdMapping = new Map();

Expand Down
5 changes: 4 additions & 1 deletion x-pack/platform/plugins/shared/onechat/server/routes/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js';
import { schema } from '@kbn/config-schema';
import { createToolIdMappings } from '@kbn/onechat-genai-utils/langchain';
import { apiPrivileges } from '../../common/features';
import type { RouteDependencies } from './types';
import { getHandlerWrapper } from './wrap_handler';
Expand Down Expand Up @@ -67,10 +68,12 @@ export function registerMCPRoutes({ router, getInternalServices, logger }: Route
const registry = await toolService.getRegistry({ request });
const tools = await registry.list({});

const idMapping = createToolIdMappings(tools);

// Expose tools scoped to the request
for (const tool of tools) {
server.tool(
tool.id,
idMapping.get(tool.id) ?? tool.id,
tool.description,
tool.schema.shape,
async (args: { [x: string]: any }) => {
Expand Down