Skip to content

Gives me error when I am trying to use it with an MCP adapter #4

@0xlel0uch

Description

@0xlel0uch

Hey! I am trying to use the codex MCP server and integrate it to my crew AI code using MCP Adapt and it seems like I get a pydantic error. I am adding the stacktrace for the same below:

Code Snippet:

import os
from dotenv import load_dotenv
from crewai import Agent, Crew, Task
from mcp import StdioServerParameters

from mcpadapt.core import MCPAdapt
from mcpadapt.crewai_adapter import CrewAIAdapter

load_dotenv()
if not os.environ.get("OPENAI_API_KEY"):
    raise ValueError("OPENAI_API_KEY must be set in your environment variables")

with MCPAdapt(
    StdioServerParameters(
        command="npx",
        args=["-y", "@codex-data/codex-mcp"],
        env={
        "CODEX_API_KEY": "<api-key>"
      },
    ),
    CrewAIAdapter(),
) as tools:
    agent = Agent(
        role="Research Agent",
        goal="Find studies about hangover",
        backstory="You help find studies about hangover",
        verbose=True,
        tools=[tools[0]],
    )

    task = Task(
        description="Find studies about hangover",
        agent=agent,
        expected_output="A list of studies about hangover",
    )

    crew = Crew(agents=[agent], tasks=[task], verbose=True)
    crew.kickoff()

Stacktrace Error:

Traceback (most recent call last):
  File "[...]/python3.13/lib/python3.13/typing.py", line 1035, in __init__
    code = compile(arg_to_compile, '<string>', 'eval')
  File "<string>", line 1
    from
    ^^^^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "[...]/project/data/crew/mcp_crew.py", line 62, in <module>
    with MCPAdapt(
         ~~~~~~~~^
        StdioServerParameters(
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
        CustomCrewAIAdapter(),
        ^^^^^^^^^^^^^^^^^^^^^^
    ) as tools:
    ^
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/core.py", line 256, in __enter__
    return self.tools()
           ~~~~~~~~~~^^
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/core.py", line 235, in tools
    self.adapter.adapt(partial(_sync_call_tool, session, tool.name), tool)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[...]/project/data/crew/mcp_crew.py", line 18, in adapt
    return super().adapt(callback, mcp_tool)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/crewai_adapter.py", line 54, in adapt
    ToolInput = create_model_from_json_schema(mcp_tool.inputSchema)
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/utils/modeling.py", line 148, in create_model_from_json_schema
    root_model = process_schema(model_name, schema)
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/utils/modeling.py", line 47, in process_schema
    field_type, default = get_field_type(field_name, field_schema, required)
                          ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/utils/modeling.py", line 79, in get_field_type
    process_schema(ref_name, ref_schema)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "[...]/project/.venv/lib/python3.13/site-packages/mcpadapt/utils/modeling.py", line 39, in process_schema
    forward_refs[name] = ForwardRef(name)
                         ~~~~~~~~~~^^^^^^
  File "[...]/python3.13/lib/python3.13/typing.py", line 1037, in __init__
    raise SyntaxError(f"Forward reference must be an expression -- got {arg!r}")
SyntaxError: Forward reference must be an expression -- got 'from'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions