Is the Filesystem MCP example in PraisonAI Documentation still working?
Discussed in https://github.com/MervinPraison/PraisonAI/discussions/463
Originally posted by edwinmyp88 April 23, 2025 I'm referring to the example in https://docs.praison.ai/mcp/filesystem I tested with both gpt-4o-mini and llama3.1 but its not listing the correct files & folders.
gpt-4o-mini returns 'don't have access to the filesystem' whereas llama3.1 hallucinates, returning random paths, files and folders that I didn't specify under the allowed_dirs variable.
Anyone else encounter this issue? Thanks in advance.
@bugbot review this error
I had a similar problem with another mcp for obisidian. I used gpt-4o-mini and gpt-4.1-2025-04-14. Considering that one of the tools for the mcp filesystem has an array parameter, I think the problem might be the same.
Long story short, mcp tools that require 'array' parameters were not initialized properly. Tools that have 'array' parameters require 'items' attribute in addition to the 'type' like the following example:
"type": "object",
"properties": {
"filepaths": {
"type": "array",
"items": {
"type": "string",
"description": "Path to a file (relative to your vault root)",
"format": "path"
},
"description": "List of file paths to read"
},
}
However, only the 'type' attribute was being sent. As a result, the agent was not calling any tools, which caused it to hallucinate.
@claude can you please review this issue and find a solution if there is a serious error. minimal code change, with backward compatibility
Claude finished @MervinPraison's task —— View job • claude/issue-619-20250627_112552 • Create PR ➔
Fixed MCP Filesystem Integration Issue ✓
I've successfully identified and fixed the issue with the Filesystem MCP example. The problem was that MCP tools with array parameters were missing the 'items' attribute required by OpenAI's function calling format.
The Problem
When MCP tools with array parameters were converted to OpenAI format, they were missing the required items attribute. For example:
MCP Schema (missing items):
{
"filepaths": {
"type": "array",
"description": "List of file paths"
}
}
Required OpenAI Schema:
{
"filepaths": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of file paths"
}
}
This caused:
- GPT-4o-mini to report "don't have access to the filesystem"
- Llama3.1 to hallucinate random paths instead of using the provided tools
The Solution
I've implemented a _fix_array_schemas() method in both mcp.py and mcp_sse.py that:
- Recursively traverses the tool schema
- Adds a default
items: {type: "string"}to any array that's missing it - Preserves existing
itemsif already present - Maintains backward compatibility by not modifying the original schema
Changes Made
-
src/praisonai-agents/praisonaiagents/mcp/mcp.py:- Added
_fix_array_schemas()method to fix array parameters - Updated
to_openai_tool()to use the fix when converting schemas
- Added
-
src/praisonai-agents/praisonaiagents/mcp/mcp_sse.py:- Added the same
_fix_array_schemas()method - Updated
to_openai_tool()to apply the fix
- Added the same
Impact
- Minimal code change: Only added the fixing logic, no breaking changes
- Backward compatible: Existing schemas without arrays or with proper
itemsremain unchanged - Fixes the issue: Array parameters now work correctly with OpenAI-compatible LLMs
The filesystem MCP example should now work properly with both gpt-4o-mini and llama3.1!
Committed
✅ Changes committed: b1307d085440e7efeacd93edf3934bf7b7eafd01
|