Error connecting to remote MCP which needs auth.
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)
/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.
/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.
Description
Error connecting to remote MCP which needs auth.
Steps to Reproduce
Expected behavior
Should connect and list the tools
Screenshots/Code snippets
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
Possible Solution
Provide auth via headers and regular browser oauth
Additional context
NA