diff --git a/ai-sdk/src/mcp-server.ts b/ai-sdk/src/mcp-server.ts index 61f98c10..73c3cdcc 100644 --- a/ai-sdk/src/mcp-server.ts +++ b/ai-sdk/src/mcp-server.ts @@ -46,7 +46,8 @@ server.registerTool( async function main() { const transport = new StdioServerTransport(); await server.connect(transport); - console.log('Pokemon MCP Server running on stdio'); + // Log to stderr: stdout is the JSON-RPC channel for a stdio MCP server. + console.error('Pokemon MCP Server running on stdio'); } main().catch((error) => { diff --git a/ai-sdk/src/worker.ts b/ai-sdk/src/worker.ts index 36d7425b..8d296ba8 100644 --- a/ai-sdk/src/worker.ts +++ b/ai-sdk/src/worker.ts @@ -1,3 +1,4 @@ +import path from 'node:path'; import { NativeConnection, Worker } from '@temporalio/worker'; import * as activities from './activities'; import { AiSdkPlugin } from '@temporalio/ai-sdk'; @@ -12,12 +13,18 @@ async function run() { try { // This is only used by the MCP Sample // @@@SNIPSTART typescript-vercel-ai-sdk-mcp-client-factories + const mcpServerPath = require.resolve('./mcp-server'); + const mcpServerArgs = mcpServerPath.endsWith('.ts') + ? ['-r', require.resolve('ts-node/register'), mcpServerPath] + : [mcpServerPath]; + const mcpClientFactories = { testServer: () => createMCPClient({ transport: new StdioClientTransport({ - command: 'node', - args: ['lib/mcp-server.js'], + command: process.execPath, + args: mcpServerArgs, + cwd: path.resolve(__dirname, '..'), }), }), };