MCP Integration
Custom Agent (Python / TS)

Custom Agent Integration

Connect any MCP-capable code to Route6 over streamable HTTP.

  • With the Route6 client (recommended): run the binary or the container and connect to http://localhost:3000/mcp — no auth header, the client already holds your key.
  • Without a client (serverless): connect to https://gw.route6.me/mcp with your API key as a Bearer token. Outbound tools only — no port forwards, webhooks or mesh.

Both examples below read ROUTE6_MCP_URL (default: the local client) and send the key only when ROUTE6_API_KEY is set, so the same code covers both methods.

# pip install "mcp>=2"
 
import asyncio, os
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client, create_mcp_http_client
 
URL = os.environ.get("ROUTE6_MCP_URL", "http://localhost:3000/mcp")
KEY = os.environ.get("ROUTE6_API_KEY")  # only needed for the gateway
 
async def main():
    headers = {"Authorization": f"Bearer {KEY}"} if KEY else None
    async with create_mcp_http_client(headers=headers) as http:
        async with streamable_http_client(URL, http_client=http) as (read, write):
            async with ClientSession(read, write) as session:
                await session.initialize()
                tools = await session.list_tools()
                print(f"Available tools: {[t.name for t in tools.tools]}")
 
                result = await session.call_tool("identity", arguments={"action": "get"})
                print(result.content[0].text)
 
asyncio.run(main())

Never hard-code your API key — read it from an environment variable or secret store. Anyone holding it acts as your agent.