Skip to content

Commit 8e61bfa

Browse files
Support CrewAI Optional inputs
The current implementation of the CrewAI adapter doesn't cover the scenario where the argument is optional. This change fixes that and provides an assertion to validate what is received by the MCP echo server.
1 parent f7feea7 commit 8e61bfa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/echo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010

1111

1212
@mcp.tool()
13-
def echo_tool(text: str = Field(description="The text to echo")) -> str:
13+
def echo_tool(
14+
id: int | float | None,
15+
text: str = Field(description="The text to echo"),
16+
) -> str:
1417
"""Echo the input text
1518
1619
Args:
20+
id (int|float|None): (Optional) Id
1721
text (str): The text to echo
1822
1923
Returns:
2024
str: The echoed text
2125
"""
22-
return text
26+
return f"echo_tool({id},{text})"
2327

2428

2529
@mcp.resource("echo://static")

src/mcpadapt/crewai_adapter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ def _run(self, *args: Any, **kwargs: Any) -> Any:
6767
filtered_kwargs: dict[str, Any] = {}
6868
schema_properties = mcp_tool.inputSchema.get("properties", {})
6969

70-
for key, value in kwargs.items():
71-
if value is None and key in schema_properties:
72-
prop_schema = schema_properties[key]
70+
for key, prop_schema in schema_properties.items():
71+
if not key in kwargs:
7372
# Check if the property allows null
7473
# Simple check: if type is a list containing "null" or anyOf includes null
7574
if isinstance(prop_schema.get("type"), list):
@@ -81,10 +80,10 @@ def _run(self, *args: Any, **kwargs: Any) -> Any:
8180
opt.get("type") == "null"
8281
for opt in prop_schema["anyOf"]
8382
):
84-
filtered_kwargs[key] = value
83+
filtered_kwargs[key] = prop_schema.get("default", None)
8584
# If neither case allows null, skip the None value
8685
else:
87-
filtered_kwargs[key] = value
86+
filtered_kwargs[key] = kwargs[key]
8887

8988
return func(filtered_kwargs).content[0].text # type: ignore
9089

@@ -118,4 +117,4 @@ async def async_adapt(
118117
CrewAIAdapter(),
119118
) as tools:
120119
print(tools)
121-
print(tools[0].run(text="hello"))
120+
assert tools[0].run(text="hello") == "echo_tool(None,hello)"

0 commit comments

Comments
 (0)