Skip to content

[BUG] An error occurred while running the crew: Failed to initialize MCP Adapter: '#/properties/geometry/anyOf/0/items' #4312

@beghou-naveenkumarmadas

Description

Description

Hi,

I am trying to connect to Mapbox MCP server as per the instructions given in https://docs.mapbox.com/help/tutorials/build-your-own-agent/?step=4, I am getting below error message when running main.py file. Please let me know how to fix this error.

Exception: An error occurred while running the crew: Failed to initialize MCP Adapter: '#/properties/geometry/anyOf/0/items'

Environment details:
Python version: 3.13.11

Thanks,
Naveen

Steps to Reproduce

I am following instructions as per https://docs.mapbox.com/help/tutorials/build-your-own-agent/?step=4 and got the error when running main.py file.

Made 2 changes as per https://docs.mapbox.com/help/tutorials/build-your-own-agent/?step=4

  1. Change1 in crew.py:
    mcp_server_params = [
    {
    "url": "https://mcp.mapbox.com/mcp",
    "transport": "streamable-http",
    "headers": {"authorization": f'Bearer {MAPBOX_ACCESS_TOKEN}'} #constant containing Mapbox API key
    }
    ]
  2. Change 2 in crew.py:
    Added parameter 'tools=self.get_mcp_tools()' in helpful_agent function.

Expected behavior

The code should connect to MCP server and answer the question.

Screenshots/Code snippets

Code in crew.py:

from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task
from crewai.agents.agent_builder.base_agent import BaseAgent
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
import os

@crewbase
class DemoProject():
"""DemoProject crew"""

agents: List[BaseAgent]
tasks: List[Task]
MAPBOX_ACCESS_TOKEN="xxxxx"

# Add mcp_server_params list, this is the first change we need to make to enable MCP
mcp_server_params = [
    {
        "url": "https://mcp.mapbox.com/mcp",
        "transport": "streamable-http",
        "headers": {"authorization": f'Bearer {MAPBOX_ACCESS_TOKEN}'}
    }
]
# "headers": {"authorization": f"Bearer {os.environ['MAPBOX_ACCESS_TOKEN']}"}

# Learn more about YAML configuration files here:
# Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended
# Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended

# If you would like to add tools to your agents, you can learn more about it here:
# https://docs.crewai.com/concepts/agents#agent-tools
@agent
def helpful_agent(self) -> Agent:
    return Agent(
        config=self.agents_config['helpful_agent'], # type: ignore[index]
        verbose=True,
        tools=self.get_mcp_tools() # This is the second change we are making to enable tools
    )

# To learn more about structured task outputs,
# task dependencies, and task callbacks, check out the documentation:
# https://docs.crewai.com/concepts/tasks#overview-of-a-task
@task
def help_task(self) -> Task:
    return Task(
        config=self.tasks_config['help_task'], # type: ignore[index]
    )


@crew
def crew(self) -> Crew:
    """Creates the DemoProject crew"""
    # To learn how to add knowledge sources to your crew, check out the documentation:
    # https://docs.crewai.com/concepts/knowledge#what-is-knowledge

    return Crew(
        agents=self.agents, # Automatically created by the @agent decorator
        tasks=self.tasks, # Automatically created by the @task decorator
        process=Process.sequential,
        verbose=True,
        # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
    )

Operating System

Windows 11

Python Version

3.12

crewAI Version

1.9.2

crewAI Tools Version

1.9.2

Virtual Environment

Venv

Evidence

python version: 3.13.11

Copied from error log:

File "....\Lib\site-packages\pydantic\json_schema.py", line 2296, in _add_json_refs
defs_ref = self.json_to_defs_refs[json_ref]
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: '#/properties/geometry/anyOf/0/items'

The above exception was the direct cause of the following exception:

File "...\Lib\site-packages\crewai_tools\adapters\mcp_adapter.py", line 125, in init
raise RuntimeError(f"Failed to initialize MCP Adapter: {e}") from e
RuntimeError: Failed to initialize MCP Adapter: '#/properties/geometry/anyOf/0/items'

During handling of the above exception, another exception occurred:

File "....\main.py", line 30, in run
raise Exception(f"An error occurred while running the crew: {e}")
Exception: An error occurred while running the crew: Failed to initialize MCP Adapter: '#/properties/geometry/anyOf/0/items'

Possible Solution

None

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions