page

MCP Server Standard (FastMCP)

fastmcp mcp standard server architecture

MCP Server Standard - FastMCP

All Nexus 3.0 MCP servers use FastMCP, the official Anthropic MCP library. This ensures protocol compliance, reduces boilerplate, and enables future updates through library upgrades.

Why FastMCP

Benefit Description
Protocol Compliance Follows official MCP spec (init → initialized → calls)
Less Boilerplate ~60 lines of JSON-RPC handling eliminated per server
Type Safety Tool schemas auto-generated from Python type hints
Maintained by Anthropic Protocol updates handled by library upgrades
Cleaner Code Business logic only, no transport plumbing

Server Structure

#!/usr/bin/env python3
"""Nexus {Environment} MCP Server v1.0.0"""

import json
import redis
from mcp.server.fastmcp import FastMCP

# Import credentials helper
import sys
sys.path.insert(0, '/opt/mcp-servers/shared')
from credentials_helper import get_environment_config

# Initialize FastMCP
mcp = FastMCP("{environment}")

# Get credentials from Locker
config = get_environment_config('{environment}')
ENV_CONFIG = {
    'vault_port': config.get('vault_port'),
    'operational_port': config.get('operational_port'),
    'vault_password': config.get('vault_password'),
}

# Manager class for business logic
class EnvironmentManager:
    def __init__(self):
        self.vault = redis.Redis(
            host='localhost',
            port=ENV_CONFIG['vault_port'],
            password=ENV_CONFIG['vault_password'],
            decode_responses=True
        )
        # Operational has no password (read-only slave)
        self.operational = redis.Redis(
            host='localhost',
            port=ENV_CONFIG['operational_port'],
            decode_responses=True
        )

manager = EnvironmentManager()

# Define tools with decorators
@mcp.tool()
async def status() -> str:
    """Get environment status."""
    # YOUR BUSINESS LOGIC HERE
    return json.dumps({'status': 'UP'})

@mcp.tool()
async def create(name: str, data: str = None) -> str:
    """Create a new item.

    Args:
        name: Item name (required)
        data: Optional data payload
    """
    # YOUR BUSINESS LOGIC HERE
    return json.dumps({'created': name})

if __name__ == "__main__":
    mcp.run()

Key Points

1. FastMCP Import

from mcp.server.fastmcp import FastMCP
mcp = FastMCP("{server_name}")

2. Tool Decorators

@mcp.tool()
async def tool_name(param: str, optional: str = None) -> str:
    """Tool description - first line becomes the tool summary.

    Args:
        param: Description of required param
        optional: Description of optional param
    """
    return json.dumps(result)

3. Main Entry Point

if __name__ == "__main__":
    mcp.run()  # FastMCP handles all protocol

Gateway Compatibility

The Gateway server (/opt/mcp-servers/gateway/mcp_gateway_server.py) sends proper MCP protocol handshakes:

  1. initialize with protocolVersion, capabilities, clientInfo
  2. notifications/initialized notification
  3. tools/call with tool name and arguments

This is required for FastMCP compliance.

Migration from Raw MCP

When converting existing servers:

  1. Replace custom class with FastMCP instance
  2. Convert methods to @mcp.tool() decorated async functions
  3. Remove manual JSON-RPC handling (~60 lines)
  4. Keep all business logic unchanged
  5. Replace if __name__ == "__main__": with mcp.run()

File Location

All MCP servers live at:

/opt/mcp-servers/{environment}/mcp_{environment}_server.py

Dependencies

pip install mcp redis

The mcp package includes FastMCP and is maintained by Anthropic.

ID: 3e9acc1e
Path: Nexus 3.0 Architecture > Nexus Environment Setup Guide > MCP Server Standard (FastMCP)
Updated: 2026-01-03T16:25:06