Skip to main content

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

Installation

Basic Agent

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:

2. Streaming Steps

Best for debugging and understanding the agent’s reasoning:
Output:

3. Stream Events (Token-Level)

Best for real-time UIs with token-by-token streaming:

LLM Providers

MCPAgent works with any LangChain-compatible LLM:
Only models with tool calling capabilities can be used with MCPAgent. Ensure your chosen model supports function calling.

Multi-Server Agents

Connect to multiple MCP servers for more capabilities:

Dynamic Server Selection

Enable smart server selection for better performance:
When 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:

Conversation Memory

Add memory for multi-turn conversations:

Observability

Monitor agent performance with Langfuse:

Setup

Create .env:

Usage

Monitoring Events

Advanced Examples

Web Research Agent

Data Analysis Agent

Travel Planning Agent

Best Practices

  • Simple tasks: 5-10 steps
  • Medium complexity: 10-20 steps
  • Complex workflows: 20-50 steps
  • Prevents infinite loops
✅ Good:
❌ Bad:
Clear instructions lead to better results.
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

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)
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
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
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