DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Classes / MCPServerAdapter
Class mcp

MCPServerAdapter: Reference Guide

By DevShelfHub

Wraps any MCP server (Stdio/SSE/HTTP) and exposes its tools as CrewAI BaseTool instances.

See the CrewAI API reference index, CrewAI introduction, and core concepts for surrounding context.

What is MCPServerAdapter?

MCPServerAdapter is the bridge between MCP transports and CrewAI's Agent tool list. You construct a server object (MCPServerStdio, MCPServerSSE, or MCPServerHTTP), pass it to the adapter, optionally layer static or dynamic filters, then spread adapter.tools into Agent(tools=[...]). That keeps agent definitions transport-agnostic while still honoring MCP schema discovery and error semantics from the upstream server.

Filters are not optional polish — they are how you prevent prompt-injection chains from surfacing dangerous tools such as arbitrary shell, credential stores, or wide-scope search. Static filters are simple allowlists; dynamic filters let you change visibility per tenant or per kickoff based on runtime context. Because MCP servers can return large manifest payloads, trimming tools also reduces planner latency and token overhead inside the LLM.

Treat adapter construction like wiring a dependency injection container: validate connectivity at startup, log tool names for audits, and version-pin remote servers so schema migrations do not break live crews.

When to Use

Whenever you integrate an MCP server.

Use Cases

  • Internal MCP services
  • Composio MCP
  • Open-source MCP servers
  • Filtered enterprise tool catalogs

Key Features

  • Transport-agnostic
  • Filter support
  • DSL shortcut
  • Mounts as BaseTool list

When NOT to Use

Stock CrewAI built-ins handle it — skip the MCP layer.

Notes

Startup connectivity checks

Fail fast during app boot if MCP is unreachable. Agents that discover missing tools mid-kickoff produce confusing partial traces.

Concurrency limits

Each tool call may open nested HTTP or stdio sessions. Cap parallel agents when upstream MCP enforces single-flight semantics.

Observability

Log tool_name, latency, and HTTP status from the adapter layer. MCP errors often stringify differently per vendor — structured logs save postmortems.

Import

python
from crewai_tools import MCPServerAdapter

Code Examples

HTTP server + static allowlist

python
from crewai import Agent
from crewai.mcp import MCPServerHTTP
from crewai.mcp.filters import create_static_tool_filter
from crewai_tools import MCPServerAdapter

adapter = MCPServerAdapter(server=MCPServerHTTP(url='https://mcp.example.com'))
adapter = adapter.with_filter(create_static_tool_filter(['search_kb', 'file_ticket']))

agent = Agent(role='Support', goal='Resolve tickets', backstory='...', tools=adapter.tools, verbose=True)

Local stdio for development

python
from crewai.mcp import MCPServerStdio
from crewai_tools import MCPServerAdapter

adapter = MCPServerAdapter(server=MCPServerStdio(command='uv', args=['run', 'python', '-m', 'local_mcp']))

Dynamic filter sketch

python
from crewai.mcp.filters import create_dynamic_tool_filter

flt = create_dynamic_tool_filter(lambda tool, ctx: tool.name in {'read_doc', 'summarize'})

adapter = MCPServerAdapter(server=server).with_filter(flt)

Common Mistakes

❌ Exposing every MCP tool blindly

✅ Apply a filter — security and prompt size.

MCPServerAdapter FAQ

What is MCPServerAdapter in CrewAI?

Wraps any MCP server (Stdio/SSE/HTTP) and exposes its tools as CrewAI BaseTool instances. MCPServerAdapter is the bridge between MCP transports and CrewAI's Agent tool list. You construct a server object (MCPServerStdio, MCPServerSSE, or MCPServerHTTP), pass it to the adapter, optionally layer static or dynamic filters, then spread adapter.tools into Agent(tools=[...]). That keeps agent definitions transport-agnostic while still honoring MCP schema discovery and error semantics from the upstream server. Filters are not optional polish — they are how you prevent p…

Which package defines the CrewAI class MCPServerAdapter?

DevShelfHub maps MCPServerAdapter to Python module crewai_tools (package path crewai_tools in this reference). Pin your installed crewai version and match imports to the snippet on this page.

When should I use MCPServerAdapter?

Whenever you integrate an MCP server.

When should I avoid using MCPServerAdapter?

Stock CrewAI built-ins handle it — skip the MCP layer.

How do I import MCPServerAdapter in Python?

from crewai_tools import MCPServerAdapter

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search 58 classes, 30 methods, and 16 decorators, each with runnable examples, parameters, common mistakes, and cross-links.