Description
What happened?
Describe the bug
I got
json_schema_to_pydantic.exceptions.TypeError: Array type must specify 'items' schema
and
ValueError: I/O operation on closed pipe
when using mcp_server_tools()
To Reproduce
Steps to reproduce the behavior. Please include code and outputs such as stacktrace.
I pulled the @negokaz/excel-mcp-server and try to build an agent for test.
npm install -g @negokaz/excel-mcp-server
First I build in VSCode with Cline for testing, and it works with this quest:
Create a excel file called test_with_autogen.xlsx with some content, and save in Desktop folder
My os is Windows 11, so my configuration is
{
"mcpServers": {
"excel": {
"command": "cmd",
"args": ["/c", "npx", "--yes", "@negokaz/excel-mcp-server"],
"env": {
"EXCEL_MCP_PAGING_CELLS_LIMIT": "4000"
}
}
}
}
Second, when I build the same excel-mcp-server in Autogen with MCP, the code is
import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import StdioServerParams, mcp_server_tools
from autogen_agentchat.agents import AssistantAgent
from autogen_core import CancellationToken
from autogen_agentchat.messages import TextMessage
from autogen_agentchat.ui import Console
async def main_excel() -> None:
server_params = StdioServerParams(
command="cmd",
args=["/c", "npx", "--yes", "@negokaz/excel-mcp-server"],
env={
"EXCEL_MCP_PAGING_CELLS_LIMIT": "4000"
}
)
# Get all available tools from the server
tools = await mcp_server_tools(server_params)
# Create an agent that can use all the tools
model_client_OpenAI = \
OpenAIChatCompletionClient(model="gpt-3.5-turbo",base_url="https://xxxxxxx/",api_key="xxxxxxxx")
agent = AssistantAgent(
name="excel",
model_client=model_client_OpenAI,
tools=tools, # type: ignore
)
# The agent can now use any of the filesystem tools
await agent.run(task="Create a excel file called test_with_autogen.xlsx with some content, and save in Desktop folder", cancellation_token=CancellationToken())
if __name__ == "__main__":
asyncio.run(main_excel())
It got the error:
Traceback (most recent call last):
File "E:\Work\AI\APEXBOT\autogen_mcp_1.py", line 71, in
asyncio.run(main_excel())
File "C:\Users\Omar\anaconda3\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\asyncio\runners.py", line 118, in run
return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\asyncio\base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "E:\Work\AI\APEXBOT\autogen_mcp_1.py", line 53, in main_excel
tools = await mcp_server_tools(server_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\autogen_ext\tools\mcp_factory.py", line 139, in mcp_server_tools
return [StdioMcpToolAdapter(server_params=server_params, tool=tool) for tool in tools.tools]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\autogen_ext\tools\mcp_stdio.py", line 48, in init
super().init(server_params=server_params, tool=tool)
File "C:\Users\Omar\anaconda3\Lib\site-packages\autogen_ext\tools\mcp_base.py", line 38, in init
input_model = create_model(tool.inputSchema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\json_schema_to_pydantic_init.py", line 42, in create_model
return builder.create_pydantic_model(schema, root_schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\json_schema_to_pydantic\model_builder.py", line 62, in create_pydantic_model
field_type = self._get_field_type(field_schema, root_schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\json_schema_to_pydantic\model_builder.py", line 98, in _get_field_type
return self.type_resolver.resolve_type(field_schema, root_schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\site-packages\json_schema_to_pydantic\resolvers.py", line 52, in resolve_type
raise TypeError("Array type must specify 'items' schema")
json_schema_to_pydantic.exceptions.TypeError: Array type must specify 'items' schema
Exception ignored in: <function BaseSubprocessTransport.del at 0x000002353D51DDA0>
Traceback (most recent call last):
File "C:\Users\Omar\anaconda3\Lib\asyncio\base_subprocess.py", line 126, in del
self.close()
File "C:\Users\Omar\anaconda3\Lib\asyncio\base_subprocess.py", line 104, in close
proto.pipe.close()
File "C:\Users\Omar\anaconda3\Lib\asyncio\proactor_events.py", line 109, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\Omar\anaconda3\Lib\asyncio\base_events.py", line 795, in call_soon
self._check_closed()
File "C:\Users\Omar\anaconda3\Lib\asyncio\base_events.py", line 541, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000002353D51F560>
Traceback (most recent call last):
File "C:\Users\Omar\anaconda3\Lib\asyncio\proactor_events.py", line 116, in del
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\asyncio\proactor_events.py", line 80, in repr
info.append(f'fd={self._sock.fileno()}')
^^^^^^^^^^^^^^^^^^^
File "C:\Users\Omar\anaconda3\Lib\asyncio\windows_utils.py", line 102, in fileno
raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe
Expected behavior
I think it has to do the same work like "VSCode + Cline", but it got errors.
Additional context
I'd build the @modelcontextprotocol\server-filesystem in Autogen, and it works. So I just want to build more MCP application for testing, like excel, but I met some problem.
Which packages was the bug in?
Python Extensions (autogen-ext)
AutoGen library version.
Python 0.4.7
Other library version.
No response
Model used
gpt-3.5-turbo
Model provider
OpenAI
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
Windows