Skip to main content
Glama
genkit-ai

Genkit MCP

Official
by genkit-ai

ジェンキットMCP

[!警告]
このプラグインは実験的なものであり、長期的にはサポートされない可能性があり、API は頻繁に重大な変更を受ける可能性があります。

このプラグインは、Genkitとモデルコンテキストプロトコル(MCP)の統合を提供します。MCPは、開発者がクライアントにツール、リソース、プロンプトを提供する「サーバー」を構築するためのオープンスタンダードです。Genkit MCPを使用すると、Genkit開発者はクライアントとしてMCPのツール、プロンプト、リソースを利用するだけでなく、サーバーとしてツールやプロンプトを提供することもできます。

インストール

始めるには、Genkit と MCP プラグインが必要です。

npm i genkit genkitx-mcp

Related MCP server: MCP Server

MCPクライアント

MCPクライアントを作成するには、 mcpClient関数を呼び出して、MCPサーバー用のGenkitプラグインを生成します。例えば、MCPのサンプルファイルシステムサーバーを使用する場合は、次のようにします。

import { genkit } from 'genkit';
import { mcpClient } from 'genkitx-mcp';

// the filesystem server requires one or more allowed directories
const ALLOWED_DIRS = ['/Users/yourusername/Desktop'];

const filesystemClient = mcpClient({
  name: 'filesystem',
  serverProcess: {
    command: 'npx',
    args: ['-y', '@modelcontextprotocol/server-everything', ...ALLOWED_DIRS],
  },
});

const ai = genkit({
  plugins: [
    filesystemClient /* ... other plugins such as model providers ...*/,
  ],
});

ほとんどのMCPサーバーは、 stdioトランスポートを使用して、同一マシン上で生成されたプロセスとして実行されるように構築されています。serverProcessオプションを指定すると、サーバーserverProcessサブプロセスとして生成するためのコマンド、引数、および環境変数が指定されます。

mcpClient() オプション

  • name : (必須) このクライアントの名前。ツールとプロンプトの名前空間を指定します。

  • version : (オプション) クライアントのバージョン番号。デフォルトは「1.0.0」です。

  • 次のいずれかを指定する必要があります:

    • serverProcess : stdio MCP トランスポートを使用してローカル サーバー プロセスを起動するためのパラメーター。

      • command : MCPサーバーを起動するためのシェルコマンドパス。パッケージマネージャーからサーバーをダウンロードして実行する場合は、例えばnpxuvxなどを使用します。

      • args : (オプション) コマンドに渡す文字列引数の配列。

      • env : (オプション) コマンドに渡す環境変数のキー値オブジェクト。

    • serverUrl : SSE MCP トランスポートを使用して接続するリモート サーバーの URL。

    • ** serverWebsocketUrl : WebSocket MCP トランスポートを使用して接続するリモート サーバーの URL。

    • transport : サーバーに接続するための既存の MCP トランスポート オブジェクト。

  • rawToolResponses : (オプション) ブール型フラグ。true true場合、ツールレスポンスは生のMCP形式で返されます。それ以外の場合は、Genkitとの互換性のために処理されます。

MCPアクションの使用

Genkit MCPクライアントは、利用可能なツールとプロンプトを自動的に検出し、Genkitに登録します。これにより、他のツールやプロンプトが使用できる場所であればどこでも利用できるようになります。リソースにアクセスするために、サーバーのリソースにアクセスするための特別なlist_resourcesread_resourceツールが登録されています。

すべての MCP アクションは指定した名前で名前空間化されるため、 filesystemというクライアントはfilesystem/read_fileなどのツールを登録します。

ツールの応答

MCPツールは、多くのGenkitツールのような構造化されたレスポンスではなく、 content配列を返します。Genkit MCPプラグインは、返されたコンテンツを解析して強制的に変換しようとします。

  1. コンテンツがテキストで有効な JSON の場合、JSON が解析されて返されます。

  2. コンテンツがテキストであり、有効な JSON ではない場合は、テキストが返されます。

  3. コンテンツにテキスト以外の部分が 1 つだけある場合は、それが返されます。

  4. コンテンツに複数の部分または混合部分がある場合は、完全なコンテンツ応答が返されます。

MCPサーバー

Genkit インスタンスからのすべてのツールとプロンプトを MCP サーバーとして公開することもできます。

import { genkit, z } from 'genkit';
import { mcpServer } from 'genkitx-mcp';

const ai = genkit({});

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}}.`
);

mcpServer(ai, { name: 'example_server', version: '0.0.1' }).start();

上記のコマンドは、stdioトランスポートを使用してMCPサーバーを起動します。stdioトランスポートは、 addというツールとhappyというプロンプトを表示します。別のトランスポートを使用してサーバーを起動するには、 mcpServer(...).start(otherTransport)使用します。

既知の制限事項

  • MCP プロンプトは文字列パラメータのみを受け入れることができるため、スキーマへの入力は文字列プロパティ値のみを持つオブジェクトである必要があります。

  • MCP プロンプトはusermodelメッセージのみをサポートします。 systemメッセージはサポートされません。

  • MCP プロンプトはメッセージ内で単一の「タイプ」のみをサポートするため、同じメッセージ内でメディアとテキストを混在させることはできません。

MCPサーバーのテスト

公式インスペクタを使ってMCPサーバーをテストできます。例えば、サーバーコードがdist/index.jsにコンパイルされている場合は、次のコマンドを実行できます。

npx @modelcontextprotocol/inspector dist/index.js

インスペクターを起動すると、プロンプトとアクションを一覧表示し、手動でテストすることができます。

A
license - permissive license
-
quality - not tested
B
maintenance

Maintenance

Maintainers
1dResponse time
5dRelease cycle
76Releases (12mo)
Issues opened vs closed

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    B
    quality
    D
    maintenance
    Implements the Model Context Protocol (MCP) to provide AI models with a standardized interface for connecting to external data sources and tools like file systems, databases, or APIs.
    1
    153
  • A
    license
    A
    quality
    C
    maintenance
    Implementation of Model Context Protocol (MCP) server that provides tools for accessing Google Cloud's Vertex AI Gemini models, supporting features like web search grounding and direct knowledge answering for coding assistance and general queries.
    20
    46
    87
    MIT
  • F
    license
    D
    quality
    D
    maintenance
    A ready-to-use starter implementation of the Model Context Protocol (MCP) server that enables applications to provide standardized context for LLMs with sample resources, tools, and prompts.
    2
    178
    1

View all related MCP servers

Related MCP Connectors

  • A Model Context Protocol server for Wix AI tools

  • MCP (Model Context Protocol) server for Appwrite

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/genkit-ai/genkit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server