Agent Integration
This guide helps AI agents use the MCP Gateway effectively. The gateway provides unified access to multiple MCP servers through a single endpoint.
Quick Start
1. list_servers() # What servers are available?
2. list_tools(server="x") # What can this server do?
3. call(server="x", tool="y", args={...}, cwd="...") # Do it
Need help? Use docs(search="your question") at any time.
Gateway Tools Reference
| Tool | Purpose | Example |
|---|---|---|
list_servers() | List available servers | list_servers(cwd="/project") |
list_all_servers() | List ALL configured servers | list_all_servers() |
list_tools(server) | List server's tools | list_tools(server="github") |
describe_tool(server, tool) | Get tool schema | describe_tool(server="github", tool="create_issue") |
call(server, tool, args, cwd) | Execute a tool | call(server="fs", tool="read_file", args={...}, cwd="...") |
list_catalog() | Browse installable servers | list_catalog() |
install_server(server, scope) | Install from catalog | install_server(server="sqlite", scope="global") |
manage_config(action, ...) | Modify gateway config | manage_config(action="get") |
docs(search) | Search documentation | docs(search="environment variables") |
Common Use Cases
"I need to use a tool but don't know what's available"
# Step 1: See available servers
list_servers()
# Step 2: Pick a server, see its tools
list_tools(server="github")
# Step 3: Get details on a specific tool
describe_tool(server="github", tool="create_issue")
# Step 4: Call the tool with project context
call(
server="github",
tool="create_issue",
args={"title": "Bug fix", "body": "..."},
cwd="/path/to/project"
)
"I need to install a new MCP server"
# Browse the catalog
list_catalog()
# Install globally (available to all projects)
install_server(server="playwright", scope="global")
# Or install for a specific project
install_server(server="playwright", cwd="/path/to/project")
Global installs require scope="global" - this prevents accidental global modifications.
"I'm getting authentication/permission errors"
# Check if you're passing project context
call(server="github", tool="...", cwd="/path/to/project") # cwd is required!
# Check what env vars the server needs
docs(search="github environment variables")
# Make sure .env file exists at project root with required vars
"I need to search documentation"
# Search for any topic
docs(search="how to configure postgres")
# Browse available topics
docs()
# Get help with errors
docs(search="MISSING_ENV_VARS error")
Project Context
Most operations need to know which project you're working in. This determines:
- Which
.envfile to load - Which servers are available
- Which credentials to use
How to Pass Context
Option 1: In every request (recommended)
call(server="x", tool="y", args={...}, cwd="/path/to/project")
Option 2: Via HTTP headers (set once per session)
X-MCP-Cwd: /path/to/project
X-MCP-Project: my-project-name
Option 3: Via project token (remote access)
When using a project-specific bearer token, the project is automatically identified from the token. No need to pass cwd or headers.
Error Handling
The gateway provides helpful errors. Always check hint and suggestion fields.
| Error Code | Meaning | What to Do |
|---|---|---|
TOOL_NOT_FOUND | Tool doesn't exist on server | Run list_tools(server="...") |
SERVER_UNAVAILABLE | Server crashed or won't start | Check logs, try install_server() |
MISSING_ENV_VARS | Server needs API keys | Add to .env file in project root |
ACCESS_DENIED | Wrong project context | Pass correct cwd parameter |
SCOPE_REQUIRED | Global change without scope | Add scope="global" to request |
Example Error Response
{
"error": "Global install requires explicit scope",
"hint": "To install globally, use: install_server(server=\"sqlite\", scope=\"global\")",
"suggestion": "install_server(server=\"sqlite\", scope=\"global\")"
}
Self-Service Help
The docs() tool searches the gateway's knowledge base. Use it when stuck:
# General questions
docs(search="how do I configure a new server")
# Error help
docs(search="what does ACCESS_DENIED mean")
# Feature questions
docs(search="http headers project context")
# Server-specific help
docs(search="postgres setup")
Configuration Changes
All config modifications require explicit scope="global":
# Install a server globally
install_server(server="sqlite", scope="global")
# Add a new server to config
manage_config(
action="add_server",
name="my-custom-server",
scope="global",
data={"url": "http://localhost:9000/mcp"}
)
# Add a new project
manage_config(
action="add_project",
name="my-app",
scope="global",
data={"path": "/home/user/my-app", "capabilities": ["github", "postgres"]}
)
# Read config (no scope needed)
manage_config(action="get")
Best Practices
- Explore before guessing - Use
list_toolsanddescribe_toolinstead of guessing tool names - Always pass context - Include
cwdin tool calls for proper credential resolution - Read error hints - The gateway tells you exactly how to fix problems
- Use docs() - Self-service help is built into the gateway
- Be explicit with scope - Config changes need
scope="global"to prevent accidents