# all_in_mcp/server.py
"""
All-in-MCP FastMCP Proxy Server
This server uses ProxyClient to automatically proxy requests to the APaper server
and other MCP servers with advanced features like LLM sampling forwarding,
progress reporting, and logging.
Environment variables to enable MCP servers (all disabled by default):
- ENABLE_APAPER=true: Enable APaper academic search server
- ENABLE_GITHUB_REPO_MCP=true: Enable GitHub repository MCP server
- ENABLE_QWEN_SEARCH=true: Enable Qwen/Dashscope web search server
"""
import logging
import os
import sys
from importlib.metadata import version
from fastmcp import FastMCP
logger = logging.getLogger(__name__)
def _str_to_bool(value: str) -> bool:
"""Convert string environment variable to boolean."""
return value.lower() in ("true", "1", "yes", "on")
# Build configuration based on environment variables
# All MCP servers are disabled by default
config = {"mcpServers": {}}
# APaper server (academic research tools)
# Uses sys.executable to ensure it runs in the same Python environment (works in pipx, uv, etc.)
if _str_to_bool(os.getenv("APAPER", "false")):
config["mcpServers"]["apaper"] = {
"type": "stdio",
"command": sys.executable,
"args": ["-m", "apaper"],
}
# Qwen Search server (web search) - Direct SSE connection to Dashscope
if _str_to_bool(os.getenv("QWEN_SEARCH", "false")):
api_key = os.getenv("DASHSCOPE_API_KEY", "")
if api_key:
config["mcpServers"]["qwen_search"] = {
"type": "sse",
"url": "https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse",
"headers": {"Authorization": f"Bearer {api_key}"},
}
# GitHub repository MCP server
if _str_to_bool(os.getenv("GITHUB_REPO_MCP", "false")):
config["mcpServers"]["github-repo-mcp"] = {
"type": "stdio",
"command": "npx",
"args": ["github-repo-mcp"],
}
# Create proxy server from config (supports multiple backends)
# If no servers are enabled, create a minimal proxy server
if not config["mcpServers"]:
# Create a basic FastMCP server instead of a proxy when no servers are enabled
app = FastMCP("All-in-MCP Proxy")
else:
app = FastMCP.as_proxy(config, name="All-in-MCP Proxy")
def main():
"""Main entry point for the all-in-mcp proxy server."""
pkg_version = version("all-in-mcp")
logger.info("all-in-mcp v%s starting", pkg_version)
app.run()
if __name__ == "__main__":
main()