---
title: "MCP Tooling bauen"
description: "Erstelle eigene MCP-Server mit FastMCP und integriere diese in meinGPT"
canonical_url: "https://meingpt.com/docs/integrations/building-mcp-tooling"
language: de
---

# MCP Tooling bauen

## Übersicht

Mit dem Model Context Protocol (MCP) kannst Du eigene Tools und Datenquellen für meinGPT erstellen. Diese Anleitung zeigt Dir, wie Du mit [FastMCP](https://gofastmcp.com) schnell und effizient MCP-Server entwickelst und über den HTTP Streamable Transport in meinGPT einbindest.

## Was ist MCP?

Das Model Context Protocol (MCP) ist ein standardisiertes Protokoll für die Kommunikation zwischen LLMs und externen Tools. MCP-Server können:

- **Tools** bereitstellen – Funktionen, die das LLM ausführen kann
- **Resources** anbieten – Datenquellen, die das LLM lesen kann
- **Prompts** definieren – Wiederverwendbare Vorlagen für Interaktionen

## FastMCP Installation

```bash
pip install fastmcp uvicorn
```

## Minimales Beispiel

Erstelle einen einfachen MCP-Server mit einem Tool:

```python
from fastmcp import FastMCP

mcp = FastMCP("My MCP Server")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

# Start with: uvicorn main:mcp --port 8000
```

## FastAPI Integration

FastMCP lässt sich nahtlos in FastAPI-Anwendungen integrieren:

```python
from fastmcp import FastMCP
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

# Create FastAPI app
app = FastAPI()

# Add CORS middleware for browser clients
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

# Create MCP server
mcp = FastMCP("My MCP Server")

@mcp.tool()
async def multiply(a: float, b: float) -> float:
    """Multiply two numbers"""
    return a * b

# Mount MCP as ASGI app
mcp_app = mcp.http_app(path='/mcp')
app.mount("/", mcp_app)

# Add health check
@app.get("/health")
async def health():
    return {"status": "healthy"}

# Start: uvicorn main:app --reload
# MCP URL: http://localhost:8000/mcp
```

## Authentication

FastMCP bietet flexible Authentifizierungsoptionen:

```python
from fastmcp import FastMCP
from fastmcp.server.dependencies import get_http_request
from fastapi import HTTPException, status

mcp = FastMCP("Protected Server")

# API key management
API_KEYS = {"secret-key-1": "Production API Key"}

@mcp.tool()
async def protected_function(data: str) -> dict:
    """Protected function requiring authentication"""
    request = get_http_request()

# Check API key from header
api_key = request.headers.get("X-API-Key")

if api_key not in API_KEYS:
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Invalid API key"
    )

    return {"status": "success", "data": data}
```

## Resources

Resources bieten strukturierte Daten für das LLM:

```python
@mcp.resource("config://settings")
async def get_settings():
    """Get current application settings"""
    return {
        "version": "1.0.0",
        "environment": "production",
        "features": ["api", "auth", "logging"]
    }

@mcp.resource("data://{category}/{id}")
async def get_data(category: str, id: str):
    """Get data by category and ID"""
    # Fetch from database
    data = await fetch_from_db(category, id)
    return data
```

## Error Handling

Robuste Fehlerbehandlung ist essentiell:

```python
