At the heart of every starship is the warp core — the matter/antimatter reactor that powers everything from life support to phaser banks. In our MCP universe, FastMCP is that reactor.
FastMCP is a high-level Python class that handles all the complexity of the MCP protocol:
You just define what your server does. FastMCP handles how it communicates.
Every warp core needs a name — the ship's registry. The name identifies your server to clients:
from mcp.server.fastmcp import FastMCP
# The ship's name is its identity in the fleet
enterprise = FastMCP('USS Enterprise')
That's it. The core is initialized. Now we need to configure its communication systems and add capabilities.
Like the ship's internal communication system — turbolifts, intercoms, direct neural links. The MCP server runs as a subprocess of the host application.
enterprise.run(transport='stdio')
Like hailing another ship via subspace — works across the network. The server exposes an HTTP endpoint that clients connect to.
enterprise = FastMCP('USS Enterprise', host='0.0.0.0', port=1701)
enterprise.run(transport='streamable-http')
Every good chief engineer (looking at you, La Forge) monitors the warp core diagnostics. Logging is essential for debugging MCP servers:
import logging
# Route diagnostics to a log file — like the ship's black box
logging.basicConfig(
filename='/tmp/enterprise.log',
level=logging.DEBUG,
format='%(asctime)s [%(name)s] %(levelname)s: %(message)s'
)
captains_log = logging.getLogger('engineering')
captains_log.info('Warp core initialization sequence begun')
During development, DEBUG level catches everything. In production, switch to INFO to reduce noise. Log to a file (not stdout!) because stdio transport uses stdout for protocol messages.
Here's a complete, operational warp core — a minimal server with one tool, proper logging, and dual-transport support:
import logging
from mcp.server.fastmcp import FastMCP
# === Engineering Diagnostics ===
logging.basicConfig(filename='/tmp/enterprise.log', level=logging.DEBUG)
log = logging.getLogger('engineering')
# === Initialize Warp Core ===
# Port 1701 — the Enterprise's registry number, naturally
enterprise = FastMCP('USS Enterprise', host='0.0.0.0', port=1701)
@enterprise.tool()
def engage_warp(factor: int) -> str:
"""Engage warp drive at specified factor.
Args:
factor: Warp factor (1-9). Factor 10 is theoretical maximum.
"""
if factor < 1 or factor > 9:
log.warning(f'Invalid warp factor requested: {factor}')
return f'Unable to comply. Warp factor {factor} exceeds safety parameters.'
log.info(f'Warp {factor} engaged')
return f'Aye sir, warp {factor} engaged. ETA to destination: {10/factor:.1f} hours.'
@enterprise.tool()
def raise_shields(power_level: int = 100) -> str:
"""Raise deflector shields to specified power level.
Args:
power_level: Shield power percentage (1-100). Default maximum.
"""
log.info(f'Shields raised to {power_level}%')
return f'Shields up. Power level: {power_level}%. All decks report ready.'
@enterprise.tool()
def fire_phaser_array(target: str, intensity: int = 5) -> str:
"""Fire phaser array at designated target.
Args:
target: Target designation (e.g., "Borg cube at bearing 215 mark 3")
intensity: Phaser intensity setting (1-16). Default: 5 (stun equivalent)
"""
log.info(f'Phasers fired at {target}, intensity {intensity}')
return f'Phaser array discharged. Target: {target}. Intensity: {intensity}. Direct hit confirmed.'
# === Main: Engage! ===
if __name__ == '__main__':
import sys
transport = 'streamable-http' if '--http' in sys.argv else 'stdio'
log.info(f'Starting MCP server with transport: {transport}')
enterprise.run(transport=transport)
Before any mission, we run a Level 1 diagnostic. The MCP CLI provides two tools:
mcp dev — Development Mode# Launches the inspector UI + your server
mcp dev warp_core.py
This opens a web-based inspector where you can:
mcp install — Register with Claude Desktop# Register the server for use with Claude Desktop
mcp install warp_core.py
After installation, Claude Desktop will see your server and can invoke its tools during conversations.
# Start the server in HTTP mode — accessible on the network
python warp_core.py --http
# Server now listening on http://0.0.0.0:1701
The warp core is online and we can fire phasers. But a starship also needs its sensor array — the ability to observe the universe. In the next log, we'll expose Resources: read-only data that the model can access on demand, like ship manifests, sensor readings, and database records.
All hands, prepare for departure.