---
title: "Building MCP Tooling"
description: "Create your own MCP servers with FastMCP and integrate them into meinGPT"
canonical_url: "https://meingpt.com/en/docs/integrations/building-mcp-tooling"
language: en
---

# Building MCP Tooling

## Overview

With the Model Context Protocol (MCP), you can create your own tools and data sources for meinGPT. This guide shows you how to quickly and efficiently develop MCP servers using [FastMCP](https://gofastmcp.com) and integrate them via HTTP Streamable Transport into meinGPT.

## What is MCP?

The Model Context Protocol (MCP) is a standardized protocol for communication between LLMs and external tools. MCP servers can:

- Provide **Tools** - functions that the LLM can execute
- Offer **Resources** - data sources that the LLM can read
- Define **Prompts** - reusable templates for interactions

## FastMCP Installation

```bash
pip install fastmcp uvicorn
```

## Minimal Example

Create a simple MCP server with a 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 integrates seamlessly with FastAPI applications:

```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 offers flexible authentication options:

```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 provide structured data for the 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

Robust error handling is essential:

```python
