in genai-function-calling/vercel-ai/mcp.js [28:51]
async function mcpServerMain(tools) {
const server = new McpServer({name, version});
// Register each tool with the server
Object.entries(tools).forEach(([toolName, tool]) => {
console.log(`Registering tool: ${toolName}`);
server.tool(
toolName,
tool.description,
tool.parameters.shape,
async (params) => {
try {
const result = await tool.execute(params);
return {content: [{type: 'text', text: result}]};
} catch (error) {
return {content: [{type: 'text', text: error.message}]};
}
}
);
});
const transport = new StdioServerTransport();
await server.connect(transport);
}