Skip to content

Genkit MCP Server gives Connection Error - Did you add the proxy session token in Configuration? #3386

@BraveEvidence

Description

@BraveEvidence

Describe the bug
I have integrated MCP server with Genkit , I am facing issue while trying to run it and it gives an error saying Genkit MCP Server gives Connection Error - Did you add the proxy session token in Configuration?

To Reproduce
Steps to reproduce the behavior:

  1. Create package.json and install
"@genkit-ai/googleai": "^1.16.0",
  "@genkit-ai/mcp": "^1.16.0",
  "genkit": "^1.16.0",
  "typescript": "^5.9.2"
  1. Create index.ts and copy the below code
import { googleAI } from "@genkit-ai/googleai";
import { createMcpServer } from "@genkit-ai/mcp";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { genkit, z } from "genkit/beta";

const ai = genkit({
  plugins: [
    googleAI({
      apiKey: "MY_API_KEY",
    }),
  ],
});

ai.defineTool(
  {
    name: "add",
    description: "add two numbers together",
    inputSchema: z.object({ a: z.number(), b: z.number() }),
    outputSchema: z.number(),
  },
  async ({ a, b }) => {
    return a + b;
  }
);

ai.definePrompt(
  {
    name: "happy",
    description: "everybody together now",
    input: {
      schema: z.object({
        action: z.string().default("clap your hands").optional(),
      }),
    },
  },
  `If you're happy and you know it, {{action}}.`
);

ai.defineResource(
  {
    name: "my resouces",
    uri: "my://resource",
  },
  async () => {
    return {
      content: [
        {
          text: "my resource",
        },
      ],
    };
  }
);

ai.defineResource(
  {
    name: "file",
    template: "file://{path}",
  },
  async ({ uri }) => {
    return {
      content: [
        {
          text: `file contents for ${uri}`,
        },
      ],
    };
  }
);

// Use createMcpServer
const server = createMcpServer(ai, {
  name: "example_server",
  version: "0.0.1",
});
// Setup (async) then starts with stdio transport by default
server.setup().then(async () => {
  await server.start();
  const transport = new StdioServerTransport();
  await server!.server?.connect(transport);
});
  1. npx tsc --init
  2. In tsconfig.json , uncomment "outDir": "dist",
  3. In package.json add "type": "module"
  4. npx tsc
  5. npx @modelcontextprotocol/inspector dist/index.js
  6. Visit http://localhost:6274 and click Connect

Expected behavior
MCP server should work with Genkit

Screenshots

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtooling

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions