#3712·genkit

[JS] MCP Tools fail on second use

Author: xOxDCreated Oct 14, 2025Updated Sep 23, 2026
Labelsbugjs

Describe the bug When using a programmatically built prompt with MCP based tools, calling the prompt a second time results in a tool not found exception even when the first execution is successful.

  • Does not appear to happen when using non-MCP tools
  • Happens with tools passed at execution time and defined in the prompt itself
  • Not tested against promptfile

To Reproduce

typescript
import { googleAI } from "@genkit-ai/google-genai";
import { genkit, z } from "genkit";
import { createMcpClient } from "@genkit-ai/mcp";

const key = process.env.GEMINI_API_KEY;

const ai = genkit({
  plugins: [googleAI()],
  model: googleAI.model("gemini-2.5-flash", {
    apiKey: key,
    thinkingConfig: {
      includeThoughts: true,
    },
  }),
});

const timeMCPClient = createMcpClient({
  name: "time",
  mcpServer: {
    command: "uvx",
    args: ["mcp-server-time"],
  },
});

await timeMCPClient.ready();
const tools = await timeMCPClient.getActiveTools(ai);

const testPrompt = ai.definePrompt({
  name: "root",
  tools: tools,
  input: {
    schema: z.object({
      prompt: z.string(),
    }),
  },
  prompt: "{{prompt}}",
});

const input = "what time is it in America/New_York?";

const rawOutput1 = await testPrompt({ prompt: input });
console.log(`result 1: ${rawOutput1.text}`);

// This throws Error: Tool /tool/mcp-time/get_current_time not found
const rawOutput2 = await testPrompt({ prompt: input });
console.log(`result 2: ${rawOutput2.text}`);
result 1: The time in America/New_York is 08:30:46 on Tuesday, October 14, 2025.
node:internal/modules/run_main:107
    triggerUncaughtException(
    ^

Error: Tool /tool/mcp-time/get_current_time not found

Expected behavior

Second execution of prompt functions correctly, just as the first.

Screenshots N/A

Runtime (please complete the following information):

  • OS: MacOS
  • Version: 14.4.1

** Node version

  • v24.8.0

Additional context N/A