Appearance
Connecting Clients
Connect your AI agents to GateFlow MCP using various frameworks and transports.
Overview
GateFlow MCP supports multiple connection methods:
LangChain
Installation
bash
pip install langchain langchain-mcpConnection
python
from langchain_mcp import MCPToolkit
# Connect to GateFlow MCP
toolkit = MCPToolkit(
server_url="https://mcp.gateflow.ai/agent_abc123",
api_key="gf-agent-xyz789..."
)
# Get available tools
tools = toolkit.get_tools()
print(f"Available tools: {[t.name for t in tools]}")Using with LangChain Agent
python
from langchain.agents import create_openai_tools_agent
from langchain_openai import ChatOpenAI
# Initialize LLM (through GateFlow)
llm = ChatOpenAI(
base_url="https://api.gateflow.ai/v1",
api_key="gw_prod_...",
model="gpt-5.2"
)
# Create agent with MCP tools
agent = create_openai_tools_agent(
llm=llm,
tools=tools,
prompt=prompt
)
# Run the agent
result = agent.invoke({"input": "Search for information about password resets"})Full Example
python
from langchain_mcp import MCPToolkit
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
# 1. Connect to MCP
toolkit = MCPToolkit(
server_url="https://mcp.gateflow.ai/agent_support_bot",
api_key="gf-agent-xyz789..."
)
tools = toolkit.get_tools()
# 2. Set up LLM
llm = ChatOpenAI(
base_url="https://api.gateflow.ai/v1",
api_key="gw_prod_...",
model="gpt-5.2"
)
# 3. Create prompt
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful support assistant. Use available tools to help users."),
("human", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad")
])
# 4. Create and run agent
agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
response = executor.invoke({"input": "How do I reset my password?"})
print(response["output"])CrewAI
Installation
bash
pip install crewai crewai-toolsConnection
python
from crewai import Agent, Task, Crew
from crewai_tools import MCPTool
# Connect to GateFlow MCP
mcp_tools = MCPTool(
server_url="https://mcp.gateflow.ai/agent_research_bot",
api_key="gf-agent-xyz789..."
)
# Create agent with MCP tools
researcher = Agent(
role="Research Assistant",
goal="Find accurate information from the knowledge base",
backstory="You are an expert researcher with access to internal documents.",
tools=[mcp_tools.search, mcp_tools.llm_chat],
verbose=True
)
# Define task
research_task = Task(
description="Research the company's refund policy",
expected_output="A summary of the refund policy",
agent=researcher
)
# Run crew
crew = Crew(agents=[researcher], tasks=[research_task])
result = crew.kickoff()Python SDK
Installation
bash
pip install gateflow-mcpDirect Connection
python
from gateflow_mcp import MCPClient
# Connect to MCP server
client = MCPClient(
agent_id="agent_abc123",
api_key="gf-agent-xyz789..."
)
# List available tools
tools = client.list_tools()
for tool in tools:
print(f"{tool.name}: {tool.description}")
# Call a tool
result = client.call_tool(
name="retrieval/search",
arguments={"query": "password reset", "limit": 5}
)
print(result)Async Usage
python
import asyncio
from gateflow_mcp import AsyncMCPClient
async def main():
async with AsyncMCPClient(
agent_id="agent_abc123",
api_key="gf-agent-xyz789..."
) as client:
# List tools
tools = await client.list_tools()
# Call tool
result = await client.call_tool(
name="llm/chat",
arguments={
"messages": [{"role": "user", "content": "Hello!"}],
"model": "gpt-5-mini"
}
)
print(result)
asyncio.run(main())Claude Desktop
Configuration
Add to your Claude Desktop config (~/.claude/config.json):
json
{
"mcpServers": {
"gateflow": {
"command": "npx",
"args": [
"gateflow-mcp-server",
"--agent-id", "agent_abc123",
"--api-key", "gf-agent-xyz789..."
]
}
}
}Using Environment Variables
json
{
"mcpServers": {
"gateflow": {
"command": "npx",
"args": ["gateflow-mcp-server"],
"env": {
"GATEFLOW_AGENT_ID": "agent_abc123",
"GATEFLOW_API_KEY": "gf-agent-xyz789..."
}
}
}
}HTTP/SSE Transport
For cloud-based agents using HTTP:
python
import httpx
class MCPHTTPClient:
def __init__(self, server_url: str, api_key: str):
self.server_url = server_url
self.headers = {"Authorization": f"Bearer {api_key}"}
def call_tool(self, name: str, arguments: dict):
response = httpx.post(
f"{self.server_url}/tools/{name}",
headers=self.headers,
json={"arguments": arguments}
)
return response.json()
def list_tools(self):
response = httpx.get(
f"{self.server_url}/tools",
headers=self.headers
)
return response.json()
# Usage
client = MCPHTTPClient(
server_url="https://mcp.gateflow.ai/agent_abc123",
api_key="gf-agent-xyz789..."
)stdio Transport
For local development with stdio:
bash
# Install the CLI
npm install -g @gateflow/mcp-server
# Run the server
gateflow-mcp-server --agent-id agent_abc123 --api-key gf-agent-xyz789...Python subprocess
python
import subprocess
import json
class MCPStdioClient:
def __init__(self, agent_id: str, api_key: str):
self.process = subprocess.Popen(
["gateflow-mcp-server", "--agent-id", agent_id, "--api-key", api_key],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True
)
def send_request(self, method: str, params: dict):
request = {"jsonrpc": "2.0", "method": method, "params": params, "id": 1}
self.process.stdin.write(json.dumps(request) + "\n")
self.process.stdin.flush()
response = self.process.stdout.readline()
return json.loads(response)Connection Options
| Option | Description | Default |
|---|---|---|
server_url | MCP server endpoint | Required |
api_key | Agent API key (gf-agent-*) | Required |
timeout | Request timeout (seconds) | 30 |
retry_attempts | Number of retries | 3 |
verify_ssl | Verify SSL certificates | true |
Troubleshooting
Connection Refused
python
# Check server URL
print(f"Connecting to: {server_url}")
# Verify API key format
if not api_key.startswith("gf-agent-"):
print("Invalid API key format")Permission Denied
json
{
"error": {
"code": "permission_denied",
"message": "Agent does not have permission for tool: voice/transcribe"
}
}Update agent permissions in the dashboard or via API.
Timeout Errors
python
# Increase timeout for long-running operations
client = MCPClient(
agent_id="agent_abc123",
api_key="gf-agent-xyz789...",
timeout=120 # 2 minutes
)Next Steps
- First Tool Invocation - Call your first tool
- Agent Templates - Pre-configured agents
- Tool Catalog - Available tools