PraisonAI icon indicating copy to clipboard operation
PraisonAI copied to clipboard

Is the Filesystem MCP example in PraisonAI Documentation still working?

Open MervinPraison opened this issue 6 months ago • 1 comments

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.

MervinPraison avatar Jun 06 '25 06:06 MervinPraison

@bugbot review this error

MervinPraison avatar Jun 06 '25 06:06 MervinPraison

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.

heesuju avatar Jun 12 '25 01:06 heesuju

@claude can you please review this issue and find a solution if there is a serious error. minimal code change, with backward compatibility

MervinPraison avatar Jun 27 '25 11:06 MervinPraison

Claude finished @MervinPraison's task —— View jobclaude/issue-619-20250627_112552Create 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:

  1. Recursively traverses the tool schema
  2. Adds a default items: {type: "string"} to any array that's missing it
  3. Preserves existing items if already present
  4. Maintains backward compatibility by not modifying the original schema

Changes Made

  1. 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
  2. src/praisonai-agents/praisonaiagents/mcp/mcp_sse.py:

    • Added the same _fix_array_schemas() method
    • Updated to_openai_tool() to apply the fix

Impact

  • Minimal code change: Only added the fixing logic, no breaking changes
  • Backward compatible: Existing schemas without arrays or with proper items remain 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

|

claude[bot] avatar Jun 27 '25 11:06 claude[bot]