crewAI-tools
crewAI-tools copied to clipboard
[BUG] Remote MCP auth issue?
Description
Error connecting to remote MCP which needs auth.
Steps to Reproduce
from crewai import Agent, Task, Crew
from crewai_tools import MCPServerAdapter
import sys # Import sys to access exception information
server_params = {
"url": "https://mcp.paypal.com/sse",
"headers": {
"Authorization": "Bearer <Token>",
}
}
try:
with MCPServerAdapter(server_params) as tools:
print("Available MCP Tools:", [tool.name for tool in tools])
doc_agent = Agent(
role="PayPal API Expert",
goal="Find answers to questions about PayPal products and APIs using the available MCP tool.",
backstory="A helpful assistant for PayPal documentation and API references.",
tools=tools,
reasoning=True,
reasoning_steps=2,
memory=True,
verbose=True
)
doc_task = Task(
description="Find the answer to: {question} using the available MCP tools.",
expected_output="A very detailed and accurate answer to the user's PayPal question.",
output_file="output/doc_answer.md",
agent=doc_agent,
markdown=True
)
crew = Crew(
agents=[doc_agent],
tasks=[doc_task],
verbose=True,
)
result = crew.kickoff(inputs={"question": input("PayPal docs, how may I help you? ") })
print("\nFinal Output:\n", result)
except RuntimeError as e:
# Catch the specific RuntimeError raised by MCPServerAdapter
print(f"Caught a RuntimeError during MCPServerAdapter initialization: {e}", file=sys.stderr)
# The original exception is the cause of this RuntimeError, which is the KeyError
original_exception = e.__cause__
if original_exception:
print(f"Original exception was: {type(original_exception).__name__}: {original_exception}", file=sys.stderr)
print("Please check the MCP server's schema or try updating the libraries.", file=sys.stderr)
except Exception as e:
# Catch any other unexpected exceptions
print(f"An unexpected error occurred: {type(e).__name__}: {e}", file=sys.stderr)
Expected behavior
Should connect and list the tools
Screenshots/Code snippets
/usr/local/lib/python3.11/dist-packages/pydantic/fields.py:1076: PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: 'items', 'anyOf', 'enum', 'properties'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/
warn(
Caught a RuntimeError during MCPServerAdapter initialization: Failed to initialize MCP Adapter: '#/properties/subscriber/properties/name'
Original exception was: KeyError: '#/properties/subscriber/properties/name'
Please check the MCP server's schema or try updating the libraries.
Operating System
Ubuntu 20.04
Python Version
3.10
crewAI Version
0.46.0 (latest)
crewAI Tools Version
0.46.0
Virtual Environment
Venv
Evidence
/usr/local/lib/python3.11/dist-packages/pydantic/fields.py:1076: PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: 'items', 'anyOf', 'enum', 'properties'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/
warn(
Caught a RuntimeError during MCPServerAdapter initialization: Failed to initialize MCP Adapter: '#/properties/subscriber/properties/name'
Original exception was: KeyError: '#/properties/subscriber/properties/name'
Please check the MCP server's schema or try updating the libraries.
Possible Solution
Provide auth via headers and regular browser oauth
Additional context
NA
+1 , for example: fastmcp client
from fastmcp.client import Client
from fastmcp.client.transports import (
StreamableHttpTransport,
)
token = ''
transport = StreamableHttpTransport(
url="http://localhost:6969/mcp",
headers={"Authorization": f"Bearer {token}"}
)
async with Client(transport) as client:
# Make calls to tools, JWT is automatically sent with every request
resp = await client.call_tool(...)
print(resp.content)
+1, any resolution on this? Or workarounds to connect a CrewAI agent to a remote MCP server that requires authentication?
Under the hood, this uses MCPAdapt, so adding auth to MCPAdapt will bring it to CrewAI as well. I have a PR in flight for authentication (OAuth, APIKey, Bearer) in general on the upstream repo https://github.com/grll/mcpadapt/pull/70