Refactor MCP server initialization and enhance Docker compatibility

- Simplified FastMCP initialization by removing unnecessary allowed_hosts parameter.
- Added logging for MCP server startup details.
- Implemented DNS rebinding protection configuration to support Docker container hostnames.
This commit is contained in:
Ke Sun
2025-12-24 11:12:45 +08:00
parent c62481571a
commit 7e28ec0f22
2 changed files with 13 additions and 4 deletions

View File

@@ -8,7 +8,4 @@ from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server instance
# This instance is shared across all tool modules
mcp = FastMCP(
'data_flow',
allowed_hosts=["mcp-server", "localhost"]
)
mcp = FastMCP('data_flow')

View File

@@ -147,6 +147,18 @@ def main():
# Get MCP port from environment (default: 8081)
mcp_port = int(os.getenv("MCP_PORT", "8081"))
logger.info(f"Starting MCP server on {settings.SERVER_IP}:{mcp_port} with SSE transport")
# Configure DNS rebinding protection for Docker container compatibility
from mcp.server.fastmcp.server import TransportSecuritySettings
# Disable DNS rebinding protection to allow Docker container hostnames
# This allows containers to connect using service names like 'mcp-server'
mcp.settings.transport_security = TransportSecuritySettings(
enable_dns_rebinding_protection=False,
)
logger.info("DNS rebinding protection: disabled for Docker container compatibility")
# logger.info(f"Starting MCP server on {settings.SERVER_IP}:{mcp_port} with SSE transport")
# Run the server with SSE transport for HTTP connections