modelcontextprotocol / modelcontextprotocol/python-sdk

Official Adapter Functions for LLM Providers in MCP Python SDK

Offen
#235 8 Kommentare 18 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement needs decision P3
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue nennt keine Dateien, Tests oder Einstiegspunkte. Kläre zunächst, welche Provider und Schemafunktionen im Umfang enthalten sind, und definiere anschließend die Adapter-API sowie anbieterspezifische Abschlussprüfungen; abgeschlossen bedeutet, dass die ausgewählten Adapter offiziell unterstützt werden und ihre Konvertierungen durch Tests abgedeckt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
ai, api
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.