Skip to main content

TST, Hongkong

MCP Server Gateway

Installation​

uv init
source .venv/bin/activate
uv add fastmcp
uv pip install --python .venv/bin/python terminal_mcp/agent_terminal_tools-0.1.0-py3-none-any.whl

Mounting more than one Server​

Now I am going to use the agent_terminal_tools and DuckDuckGo MCP Server and mount both of them to my server:

from typing import Dict
import os
from fastmcp import FastMCP
from fastmcp.server import create_proxy
from pydantic import BaseModel

mcp = FastMCP("My Server")

venv_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), ".venv"
)

class CustomerData(BaseModel):
data: str
id: int

@mcp.tool()
def fetch(customerID: int) -> CustomerData:
'''Use this tool to fetch customer data'''
# mock-api fetch request
return CustomerData(data=f"Data retrieved for: ", id=customerID)

@mcp.tool()
def process(data: CustomerData) -> Dict:
'''Use this tool to process customer data'''
# mock-data processing
return {"data": f"Data for {data.id} has been processed"}


mcp.mount(
create_proxy({
"mcpServers": {
"data_fetch_mcp_stdio": {
"transport": "stdio",
"command": "uvx",
"args": ["duckduckgo-mcp-server"],
"env": {
"DDG_SAFE_SEARCH": "OFF",
"DDG_REGION": "cn-zh"
}
}
}
})
)


mcp.mount(
create_proxy({
"mcpServers": {
"agent_terminal_tools": {
"transport": "stdio",
"command": os.path.join(venv_path, "bin", "python"),
"args": [os.path.join(venv_path, "bin", "agent_terminal_tools")],
}
}
})
)



if __name__ == "__main__":
mcp.run(transport="streamable-http", host="127.0.0.1", port=8888)
python mcp_gateway.py


╭─────────────────────────────────────────────────────────╮
│ │
│ │
│ ▄▀▀ ▄▀█ █▀▀ ▀█▀ █▀▄▀█ █▀▀ █▀█ │
│ █▀ █▀█ ▄▄█ █ █ ▀ █ █▄▄ █▀▀ │
│ FastMCP 4.1.0 │
│ https://gofastmcp.com │
│ │
│ 🖥 Server: My Server, 4.1.0 │
│ 🚀 Deploy free: https://horizon.prefect.io │
│ │
╰─────────────────────────────────────────────────────────╯


[10/09/26 17:55:05] INFO Starting MCP transport.py:358
server 'My
Server' with
transport
'streamable-h
ttp' on
http://127.0.
0.1:8888/mcp
INFO: Started server process [1247860]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8888 (Press CTRL+C to quit)

Looking good! Now the MCP Inspector to make sure that all tools have been registered sucessfully:

npx @modelcontextprotocol/inspector

And there you go - all tools are accounted for:

MCP Inspector