Skip to content
weego edited this page May 28, 2026 · 1 revision

MCP

LightAgent can register tools from Model Context Protocol servers. It supports stdio and SSE transports through the mcp Python package.

Configuration Shape

MCP settings are passed as a dictionary with mcpServers:

mcp_settings = {
    "mcpServers": {
        "weather-stdio": {
            "command": "python",
            "args": ["./mcp/mcpServers/mcpServer_demo_stdio.py"],
            "disabled": False,
        },
        "weather-sse": {
            "url": "http://localhost:8000/sse",
            "headers": {
                "Authorization": "Bearer token",
            },
            "disabled": True,
        },
    }
}

Set disabled to False for servers that should be connected.

Register MCP Tools

setup_mcp() is async:

import asyncio
from LightAgent import LightAgent

agent = LightAgent(
    model="gpt-4.1",
    api_key="your_api_key",
    base_url="https://api.openai.com/v1",
)

asyncio.run(agent.setup_mcp(mcp_setting=mcp_settings))

response = agent.run("Use the available MCP tools to check the weather.")
print(response)

During setup, LightAgent lists tools from enabled MCP servers and adds them to the agent tool registry.

Stdio Servers

Use stdio for local MCP servers:

{
    "command": "python",
    "args": ["./mcp/mcpServers/mcpServer_demo_stdio.py"],
    "env": {"SOME_KEY": "value"},
    "disabled": False,
}

Validate the command independently before connecting it to LightAgent.

SSE Servers

Use SSE for remote or long-running MCP servers:

{
    "url": "http://localhost:8000/sse",
    "headers": {
        "Content-Type": "application/json",
        "Authorization": "Bearer token",
    },
    "disabled": False,
}

Confirm the SSE endpoint is reachable before debugging the agent layer.

Troubleshooting

  • If no MCP tools appear, check disabled, command paths, and server startup logs.
  • If a stdio server fails, run the command directly in a terminal.
  • If an SSE server fails, test the endpoint and headers independently.
  • If a tool call fails, check the MCP tool input schema and required arguments.
  • Keep MCP server credentials out of committed files.

Reference files:

Clone this wiki locally