modelcontextprotocol / modelcontextprotocol/python-sdk

Official Adapter Functions for LLM Providers in MCP Python SDK

オープン
#235 コメント 8 件 リアクション 18 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement needs decision P3
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

Is your feature request related to a problem? Please describe.

Currently, when integrating MCP tools with various LLM providers, developers must implement their own adapter functions to convert MCP tool schemas to the target provider’s format. This repetitive and manual process increases development time and introduces potential inconsistencies and errors across different implementations. For example, while one developer may create a conversion adapter for the Gemini tool, another might duplicate the effort in their own project, leading to fragmented solutions and maintenance challenges.

Describe the solution you'd like

I propose that the official Python SDK for Model Context Server includes a suite of built-in adapter functions to facilitate seamless conversion from MCP tool schemas to those required by popular LLM providers (e.g., Gemini, GPT-4, etc.). By providing these adapters, the SDK would:

  • Standardize the conversion process across projects.
  • Reduce development time and prevent duplication of code.
  • Enhance consistency and reliability when integrating with multiple LLM providers.
  • Allow developers to focus on higher-level integration concerns rather than schema translation.

Describe alternatives you've considered

One alternative is for each developer to write their own adapter functions, as demonstrated by the sample code below. However, this approach is inefficient and can lead to fragmented and non-standardized implementations. Another alternative would be to provide partial documentation and code snippets as guidance, but without official support, developers might still encounter integration challenges and maintenance issues.

Additional context

The inclusion of official adapters would not only streamline the integration process for MCP clients but also foster a more robust and unified ecosystem. The sample code below illustrates how a conversion function from an MCP tool to a Gemini tool might look, serving as a basis for the kind of functionality that should be officially supported:

from google.genai import types as genai_types
from mcp import types as mcp_types

def to_gemini_tool(mcp_tool: mcp_types.Tool) -> genai_types.Tool:
    """
    Converts an MCP tool schema to a Gemini tool.

    Args:
        mcp_tool: The MCP tool containing name, description, and input schema.

    Returns:
        A Gemini tool with the appropriate function declaration.
    """
    function_declaration = to_gemini_function_declarations(mcp_tool)
    return genai_types.Tool(function_declarations=[function_declaration])

def to_gemini_function_declarations(
    mcp_tool: mcp_types.Tool,
) -> genai_types.FunctionDeclarationDict:
    required_params: list[str] = mcp_tool.inputSchema.get("required", [])
    properties = {}
    for key, value in mcp_tool.inputSchema.get("properties", {}).items():
        schema_dict = {
            "type": value.get("type", "STRING").upper(),
            "description": value.get("description", ""),
        }
        properties[key] = genai_types.SchemaDict(**schema_dict)

    function_declaration = genai_types.FunctionDeclarationDict(
        name=mcp_tool.name,
        description=mcp_tool.description,
        parameters=genai_types.SchemaDict(
            type="OBJECT",
            properties=properties,
            required=required_params,
        ),
    )
    return function_declaration

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue ではファイル、テスト、エントリーポイントが指定されていません。まず、どのプロバイダーとスキーマ機能を対象とするのかを明確にし、次に adapter API とプロバイダー固有の完了チェックを定義します; 選択したアダプターが正式にサポートされ、その変換がテストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
ai, api
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。