@mondaydotcomorg/atp-mcp-adapter
Version:
MCP compatibility adapter for Agent Tool Protocol
71 lines • 2.67 kB
JavaScript
/**
* Registers ATP tools with an MCP server.
*
* @example
* ```typescript
* import { Server } from '@modelcontextprotocol/sdk/server/index.js';
* import { AgentToolProtocolClient } from '@mondaydotcomorg/atp-client';
* import { registerATPTools } from '@mondaydotcomorg/atp-mcp-adapter';
*
* const client = new AgentToolProtocolClient({ baseUrl: 'http://localhost:3000' });
* await client.init();
* await client.connect();
*
* const mcpServer = new Server({ name: 'my-server', version: '1.0.0' }, { capabilities: { tools: {} } });
* registerATPTools(client, mcpServer);
* ```
*/
export function registerATPTools(client, mcpServer) {
const tools = client.getATPTools();
registerToolsWithMCP(tools, mcpServer);
}
/**
* Registers an array of ATP tools with an MCP server.
* Use this if you want more control over which tools to register.
* Supports both MCP SDK v0.x and v1.x APIs.
*
* @example
* ```typescript
* const tools = client.getATPTools().filter(t => t.name !== 'search_api');
* registerToolsWithMCP(tools, mcpServer);
* ```
*/
export function registerToolsWithMCP(tools, mcpServer) {
for (const tool of tools) {
const handler = async (args) => {
try {
const result = await tool.func(args);
const resultText = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
return {
content: [{ type: 'text', text: resultText }],
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{ type: 'text', text: `Error: ${errorMessage}` }],
isError: true,
};
}
};
if (typeof mcpServer.registerTool === 'function') {
const inputSchema = tool.zodSchema?.shape ?? {};
mcpServer.registerTool(tool.name, {
description: tool.description || '',
inputSchema,
}, handler);
}
else if (typeof mcpServer.tool === 'function') {
const jsonSchema = {
type: tool.inputSchema.type,
properties: tool.inputSchema.properties || {},
required: tool.inputSchema.required || [],
};
mcpServer.tool(tool.name, tool.description || '', jsonSchema, handler);
}
else {
throw new Error('MCP server does not have a compatible tool registration method. Expected registerTool() or tool() method.');
}
}
}
//# sourceMappingURL=atp-to-mcp.js.map