Skip to content

Bug: Filter out None values in _run method of crewai_adapter.py #46

@freddo1503

Description

@freddo1503

Description

When running a CrewAI agent that uses the list_pull_requests tool from the GitHub MCP server, the following error is encountered:

parameter head is not of type string, is <nil>

Error Response from the MCP server

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "parameter head is not of type string, is \u003cnil\u003e"
      }
    ],
    "isError": true
  }
}

Steps to Reproduce

  1. Run the agent using the code below.
import os
from mcp import StdioServerParameters
from crewai import Agent, Task, Crew
from crewai_tools import MCPServerAdapter

GITHUB_TOKEN = os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN")
GITHUB_USER = os.getenv("GITHUB_USERNAME")
GITHUB_REPO = os.getenv("GITHUB_REPOSITORY")

if not GITHUB_TOKEN:
    raise EnvironmentError("Please set the GITHUB_PERSONAL_ACCESS_TOKEN environment variable.")

server_params = StdioServerParameters(
    command="docker",
    args=[
        "run", "-i", "--rm",
        "-e", f"GITHUB_PERSONAL_ACCESS_TOKEN={GITHUB_TOKEN}",
        "ghcr.io/github/github-mcp-server"
    ]
)

with MCPServerAdapter(server_params) as tools:
    agent = Agent(
        role="GitHub Pull Request Analyst",
        goal="Identify and summarize open pull requests",
        backstory="You specialize in GitHub workflows and analyze open PRs.",
        tools=tools,
        verbose=True
    )

    task = Task(
        description=(
            f"Retrieve and summarize open PRs for '{GITHUB_USER}/{GITHUB_REPO}' "
            f"using the 'list_pull_requests' tool. Only pass non-empty fields as strings."
        ),
        expected_output=(
            f"- PR number\n- Title\n- Status\n- Author\n- Optional summary"
        ),
        agent=agent
    )

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

Proposed Fix (in crewai_adapter.py)

Current:

def _run(self, *args: Any, **kwargs: Any) -> Any:
    print("args", args)
    print("kwargs", kwargs)
    return func(kwargs).content[0].text

Suggested:

def _run(self, *args: Any, **kwargs: Any) -> Any:
    print("args", args)
    print("kwargs", kwargs)
    processed_kwargs = {k: v for k, v in kwargs.items() if v is not None}
    return func(processed_kwargs).content[0].text

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions