mcp-infra
An MCP server that provides tools for filesystem, database, web, system, and shell operations, along with resources and prompts via SSE transport.
README
đïž MCP Infrastructure
Eine vollstÀndige Model Context Protocol (MCP) Implementierung in Python mit SSE-Transport, die Tools, Resources und Prompts bereitstellt.
đ Ăberblick
Dieses Projekt implementiert das offizielle MCP-Protokoll von Anthropic und bietet:
- MCP Server mit SSE (Server-Sent Events) Transport
- MCP Client zum Testen und zur Interaktion
- 11 Tools fĂŒr Dateisystem, Datenbank, Web, System und Shell-Operationen
- Resources fĂŒr strukturierten Zugriff auf Daten
- Prompt Templates fĂŒr hĂ€ufige Aufgaben
đ Features
Tools (Funktionen)
Dateisystem
read_file- Dateiinhalte lesenwrite_file- Dateien schreibenlist_directory- Verzeichnisinhalte auflisten
Datenbank
query_sqlite- SELECT-Abfragen ausfĂŒhrenexecute_sql- INSERT/UPDATE/DELETE ausfĂŒhrenlist_tables- Tabellen auflisten
Web/API
fetch_url- URLs abrufenhttp_request- HTTP-Requests mit Custom-Headers
System
get_system_info- System-Informationen (CPU, RAM, Disk)list_processes- Laufende Prozesse auflisten
Shell
execute_shell_command- Shell-Befehle ausfĂŒhren
Resources (Datenquellen)
- file:// - Dateien als Resources
- db:// - Datenbank-Tabellen als Resources
- system:// - System-Informationen als Resources
Prompts (Templates)
code_review- Code-Review-Assistentsql_helper- SQL-Query-Generatorsystem_diagnostics- System-Diagnose-Helferapi_integration- API-Integration-Guide
đŠ Installation
1. Repository klonen und Setup
cd mcp-infrastructure
python -m venv venv
source venv/bin/activate # Auf Windows: venv\Scripts\activate
pip install -r requirements.txt
2. AbhÀngigkeiten
Das Projekt benötigt:
- Python 3.10+
- MCP Python SDK
- aiohttp (fĂŒr SSE-Server)
- aiosqlite (fĂŒr Datenbank-Tools)
- httpx (fĂŒr HTTP-Tools)
- psutil (fĂŒr System-Tools)
đŻ Verwendung
Server starten
cd server
python main.py
Der Server lÀuft auf:
- HTTP:
http://localhost:8000 - SSE Endpoint:
http://localhost:8000/sse - Messages Endpoint:
http://localhost:8000/messages
Client Demo ausfĂŒhren
cd client
python client.py
Die Demo zeigt:
- Verbindung zum Server
- Auflistung aller Tools, Resources und Prompts
- Beispiel-Aufrufe von Tools
- Lesen von Resources
- Verwendung von Prompts
Eigenen Client erstellen
import asyncio
from mcp import ClientSession
from mcp.client.sse import sse_client
async def main():
async with sse_client("http://localhost:8000/sse") as (read, write):
async with ClientSession(read, write) as session:
# Initialize
await session.initialize()
# List tools
tools = await session.list_tools()
print(f"Available tools: {[t.name for t in tools.tools]}")
# Call a tool
result = await session.call_tool("get_system_info", {})
print(f"Result: {result.content}")
# Read a resource
resource = await session.read_resource("system://info")
print(f"Resource: {resource.contents}")
# Get a prompt
prompt = await session.get_prompt(
"code_review",
{"code": "def hello(): return 'world'"}
)
print(f"Prompt: {prompt.messages}")
asyncio.run(main())
đïž Projektstruktur
mcp-infrastructure/
âââ README.md # Diese Datei
âââ requirements.txt # Python-AbhĂ€ngigkeiten
â
âââ server/ # MCP Server
â âââ main.py # Server-Hauptdatei (SSE Transport)
â âââ tools/ # Tool-Implementierungen
â â âââ filesystem.py # Dateisystem-Tools
â â âââ database.py # Datenbank-Tools
â â âââ web.py # Web/API-Tools
â â âââ system.py # System-Tools
â â âââ shell.py # Shell-Tools
â âââ resources/ # Resource-Provider
â â âââ providers.py # File/DB/System Resource Provider
â âââ prompts/ # Prompt-Templates
â âââ templates.py # Template-Definitionen
â
âââ client/ # MCP Client
â âââ client.py # Client-Implementierung + Demo
â
âââ tests/ # Tests (TODO)
âââ ...
đ§ Konfiguration
Server-Port Àndern
In server/main.py:
site = web.TCPSite(runner, "localhost", 8000) # Port hier Àndern
Timeout fĂŒr Shell-Befehle anpassen
In server/tools/shell.py:
async def execute_shell_command(command: str, timeout: int = 30): # Timeout hier
đĄ MCP Protokoll
Dieses Projekt implementiert das offizielle Model Context Protocol (MCP) von Anthropic:
- Transport: SSE (Server-Sent Events) ĂŒber HTTP
- Capabilities: Tools, Resources, Prompts
- SDK: Verwendet das offizielle
mcpPython-Paket
Protokoll-Flow
- Client verbindet sich via SSE zum
/sseEndpoint - Initialize: Client sendet Initialisierung
- Capabilities: Server antwortet mit verfĂŒgbaren Tools/Resources/Prompts
- Requests: Client kann Tools aufrufen, Resources lesen, Prompts abrufen
- Responses: Server antwortet mit strukturierten Daten
đ Learning Path
1. Grundlagen verstehen
- Lies die offizielle MCP-Dokumentation
- Verstehe Tools, Resources und Prompts
- Lerne SSE (Server-Sent Events)
2. Server erkunden
- Starte den Server und öffne
server/main.py - Schaue dir die Tool-Registrierung an (
@app.list_tools()) - Verstehe wie Tools aufgerufen werden (
@app.call_tool())
3. Client ausprobieren
- FĂŒhre
client/client.pyaus - Modifiziere die Demo-Aufrufe
- Erstelle eigene Client-Interaktionen
4. Erweitern
- FĂŒge neue Tools hinzu (z.B. E-Mail-Versand)
- Erstelle neue Resources (z.B. Git-Repositories)
- Entwickle neue Prompt-Templates
đ Sicherheitshinweise
â ïž WICHTIG: Dieses Projekt ist fĂŒr Learning/Experimentieren gedacht!
Produktions-Ăberlegungen:
-
Shell-Befehle:
execute_shell_commandkann beliebige Befehle ausfĂŒhren- Implementiere Whitelisting/Sandboxing
- Validiere Input streng
-
Dateisystem-Zugriff: Tools haben Zugriff auf das gesamte Dateisystem
- BeschrÀnke auf bestimmte Verzeichnisse
- Implementiere Permissions
-
Datenbank-Zugriff: SQL-Injection-Gefahr
- Verwende Prepared Statements
- Validiere Queries
-
HTTP-Requests: SSRF-Gefahr (Server-Side Request Forgery)
- Blocke interne IPs
- Implementiere Rate-Limiting
-
Authentication: Aktuell keine Authentifizierung
- FĂŒge API-Keys hinzu
- Implementiere OAuth/JWT
đ§Ș Testing
Tools testen
# Server starten
cd server && python main.py
# In anderem Terminal: Client ausfĂŒhren
cd client && python client.py
Einzelne Tools testen
from server.tools.filesystem import read_file
import asyncio
result = asyncio.run(read_file("README.md"))
print(result)
đ ïž Entwicklung
Neue Tools hinzufĂŒgen
- Erstelle Funktion in
server/tools/ - Registriere in
server/main.pybei@app.list_tools() - Handle in
@app.call_tool()
Beispiel:
# In server/tools/email.py
async def send_email(to: str, subject: str, body: str):
# Implementation
return {"success": True}
# In server/main.py
@app.list_tools()
async def list_tools():
return [
# ... existing tools
types.Tool(
name="send_email",
description="Send an email",
inputSchema={
"type": "object",
"properties": {
"to": {"type": "string"},
"subject": {"type": "string"},
"body": {"type": "string"}
},
"required": ["to", "subject", "body"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: Any):
if name == "send_email":
result = await send_email(
arguments["to"],
arguments["subject"],
arguments["body"]
)
# ... handle other tools
đ Ressourcen
đ€ BeitrĂ€ge
Dieses Projekt ist ein Learning-Projekt. FĂŒhle dich frei:
- Issues zu erstellen
- Pull Requests einzureichen
- Verbesserungen vorzuschlagen
đ Lizenz
MIT License - Frei verwendbar fĂŒr Learning und Experimente
đŻ Roadmap
- [ ] Unit Tests hinzufĂŒgen
- [ ] WebSocket-Transport implementieren
- [ ] Authentication/Authorization
- [ ] Docker-Container
- [ ] Mehr Tools (Git, Docker, etc.)
- [ ] Web-UI fĂŒr Testing
- [ ] Logging und Monitoring
- [ ] Rate Limiting
- [ ] Input Validation/Sanitization
đĄ Beispiele
Beispiel 1: Datei lesen und analysieren
# Mit Client
result = await session.call_tool("read_file", {"path": "data.txt"})
# Dann verwende ein Prompt
prompt = await session.get_prompt("code_review", {"code": result.content[0].text})
Beispiel 2: Datenbank abfragen
# Tabellen auflisten
tables = await session.call_tool("list_tables", {"db_path": "app.db"})
# Query ausfĂŒhren
result = await session.call_tool("query_sqlite", {
"db_path": "app.db",
"query": "SELECT * FROM users LIMIT 10"
})
Beispiel 3: System-Diagnose
# System-Info abrufen
info = await session.call_tool("get_system_info", {})
# Mit Diagnostics-Prompt kombinieren
prompt = await session.get_prompt("system_diagnostics", {
"issue": f"High memory usage: {info.content[0].text}"
})
đ Troubleshooting
Server startet nicht
- PrĂŒfe ob Port 8000 frei ist:
lsof -i :8000 - Ăndere Port in
main.py
Client kann nicht verbinden
- Stelle sicher, dass Server lÀuft
- PrĂŒfe URL:
http://localhost:8000/sse - ĂberprĂŒfe Firewall-Einstellungen
Tools funktionieren nicht
- PrĂŒfe Logs im Server
- Validiere Input-Parameter
- Teste Tools direkt (siehe Testing)
Happy MCP Learning! đ
Bei Fragen oder Problemen, erstelle ein Issue im Repository.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.