What are MCP Agents?
MCP Agents are AI-powered assistants that can reason, plan, and execute actions using tools from MCP servers. They combine Large Language Models (LLMs) with MCP tools to accomplish complex, multi-step tasks.Autonomous
Agents reason about tasks and decide which tools to use
Tool-Enabled
Access to any MCP server’s tools, resources, and prompts
Multi-Step
Execute complex workflows across multiple tools
LLM-Agnostic
Works with OpenAI, Anthropic, Groq, and more
Quick Start
Agent Execution Modes
MCPAgent supports three execution modes for different use cases:1. Simple Run (Blocking)
Best for simple queries where you only need the final result:- TypeScript
- Python
2. Streaming Steps
Best for debugging and understanding the agent’s reasoning:- TypeScript
- Python
3. Stream Events (Token-Level)
Best for real-time UIs with token-by-token streaming:- TypeScript
- Python
LLM Providers
MCPAgent works with any LangChain-compatible LLM:- TypeScript
- Python
Multi-Server Agents
Connect to multiple MCP servers for more capabilities:- TypeScript
- Python
Dynamic Server Selection
Enable smart server selection for better performance:- TypeScript
- Python
useServerManager is enabled:- Agent only sees relevant tools for each step
- Reduces context window usage
- Improves tool selection accuracy
- Faster execution
Tool Access Control
Restrict which tools the agent can access:- TypeScript
- Python
Conversation Memory
Add memory for multi-turn conversations:- TypeScript
- Python
Observability
Monitor agent performance with Langfuse:Advanced Examples
Web Research Agent
- TypeScript
- Python
Data Analysis Agent
Travel Planning Agent
Best Practices
Set Appropriate Max Steps
Set Appropriate Max Steps
- Simple tasks: 5-10 steps
- Medium complexity: 10-20 steps
- Complex workflows: 20-50 steps
- Prevents infinite loops
Use Specific Instructions
Use Specific Instructions
✅ Good:❌ Bad:Clear instructions lead to better results.
Handle Errors Gracefully
Handle Errors Gracefully
Monitor Token Usage
Monitor Token Usage
Test with Different LLMs
Test with Different LLMs
Different LLMs have different strengths:
- GPT-4o: Best overall, excellent tool calling
- Claude Sonnet: Great reasoning, good for complex tasks
- GPT-3.5: Fast, cost-effective for simple tasks
- Llama 3: Free, good for privacy-sensitive applications
Troubleshooting
Agent Not Using Tools
Agent Not Using Tools
Problem: Agent returns answers without calling toolsSolutions:
- Make instructions more explicit
- Verify tools are loaded:
await client.getTools() - Check LLM supports tool calling
- Increase temperature slightly (0.1-0.3)
Agent Repeating Actions
Agent Repeating Actions
Problem: Agent calls same tool multiple timesSolutions:
- Reduce maxSteps
- Make tool descriptions clearer
- Add explicit “stop” conditions in prompt
- Use streaming to detect loops early
Hitting Max Steps
Hitting Max Steps
Problem: Agent exceeds maximum stepsSolutions:
- Break task into smaller subtasks
- Increase maxSteps if task is legitimately complex
- Simplify the query
- Check for tool errors causing retries
Tool Call Failures
Tool Call Failures
Problem: Tools fail during executionSolutions:
- Verify server is running
- Check tool parameters
- Look at server logs
- Test tools directly in inspector
Next Steps
Build MCP Servers
Create custom MCP servers for your agents
Deploy Agents
Deploy agents to production with Manufact
Examples
Browse agent examples and templates
API Reference
Complete agent API documentation