Appearance
Create Your First Agent
This guide walks you through creating and using your first MCP agent.
Prerequisites
- GateFlow account with API key
- At least one provider configured (OpenAI, Anthropic, etc.)
Step 1: Create an Agent
bash
curl -X POST https://api.gateflow.ai/v1/mcp/agents \
-H "Authorization: Bearer gw_prod_..." \
-H "Content-Type: application/json" \
-d '{
"name": "My First Agent",
"description": "A simple chatbot agent",
"permissions": {
"tools": ["llm/chat"],
"models": ["gpt-4o-mini"]
}
}'Response:
json
{
"agent_id": "agent_abc123",
"name": "My First Agent",
"api_key": "gf-agent-xyz789...",
"mcp_endpoint": "https://mcp.gateflow.ai/agent_abc123",
"permissions": {
"tools": ["llm/chat"],
"models": ["gpt-4o-mini"]
}
}Save Your Agent Key
The api_key is only shown once. Store it securely.
Step 2: Connect to the Agent
Using Python
python
import httpx
class MCPAgent:
def __init__(self, endpoint: str, api_key: str):
self.endpoint = endpoint
self.api_key = api_key
self.client = httpx.Client()
def call_tool(self, tool: str, params: dict):
response = self.client.post(
f"{self.endpoint}/tools/{tool}",
headers={"Authorization": f"Bearer {self.api_key}"},
json=params
)
return response.json()
agent = MCPAgent(
endpoint="https://mcp.gateflow.ai/agent_abc123",
api_key="gf-agent-xyz789..."
)Using LangChain
python
from langchain_community.tools import MCPToolkit
toolkit = MCPToolkit(
server_url="https://mcp.gateflow.ai/agent_abc123",
api_key="gf-agent-xyz789..."
)
tools = toolkit.get_tools()Step 3: Use a Tool
python
# Call the chat tool
result = agent.call_tool("llm/chat", {
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello! What can you do?"}
]
})
print(result["response"]["content"])Output:
Hello! I'm an AI assistant. I can help you with:
- Answering questions
- Having conversations
- Providing information
How can I help you today?Step 4: Check Usage
python
# Use the self-inspect tool
usage = agent.call_tool("self/whoami", {})
print(f"Agent: {usage['agent_name']}")
print(f"Session cost: ${usage['session_cost']}")
print(f"Tools available: {usage['tools']}")Step 5: View Audit Log
Check what your agent did:
bash
curl https://api.gateflow.ai/v1/mcp/agents/agent_abc123/audit-log \
-H "Authorization: Bearer gw_prod_..." \
-G -d "limit=10"Complete Example
python
import httpx
import json
# Configuration
AGENT_ENDPOINT = "https://mcp.gateflow.ai/agent_abc123"
AGENT_KEY = "gf-agent-xyz789..."
def chat(message: str) -> str:
"""Send a message to the agent and get a response."""
response = httpx.post(
f"{AGENT_ENDPOINT}/tools/llm/chat",
headers={"Authorization": f"Bearer {AGENT_KEY}"},
json={
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": message}]
}
)
result = response.json()
return result["response"]["content"]
# Have a conversation
print(chat("What is the capital of France?"))
print(chat("What's the population?"))
print(chat("Tell me an interesting fact about it."))Next Steps
- Agent Templates - Pre-built agent configurations
- Connecting Clients - More client options
- First Tool Invocation - Deep dive into tools