[Python] How to improve function calling of server-filesystem mcp server with openai model

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a working model that I can talk to with two configured mcp servers. The first one is the pydantic Python executer and the second one is the mcp filesystem server. Both are recognized by the model and I can execute Python code, the model correctly chooses the tool and executed Python code when needed.

    But with the filesystem server I can't really get the model to read files. It always responds with: "To read the content of a file you need to use read_file(path: ...)"

    I'm using the mcp-openai library: https://github.com/S1M0N38/mcp-openai/tree/main

    mcp_client_config = config.MCPClientConfig(
    mcpServers={
    "pydantic_server": config.MCPServerConfig(
    command='deno',
    args=[
    'run',
    '-N',
    '-R=node_modules',
    '-W=node_modules',
    '--node-modules-dir=auto',
    'jsr:mad:pydantic/mcp-run-python',
    'stdio',
    ],
    ),
    "filesystem": config.MCPServerConfig(
    command = "npx",
    args= [
    "-y",
    "@modelcontextprotocol/server-filesystem",
    "/app/test"
    ]
    )
    }
    )


    This is how I configured my client and this is my main loop:

    async def interactive_loop():
    for server in mcp_client_config.mcpServers:
    await client.connect_to_server(server)
    await asyncio.sleep(1)

    print("MCP Client gestartet. Schreibe 'quit' zum Beenden.")

    messages = []

    try:
    while True:
    user_input = input("\nUser: ").strip()
    if user_input.lower() in {"quit", "exit"}:
    print("Beende.")

    break

    messages.append({
    "role": "user",
    "content": user_input
    })

    try:
    messages_out = await client.process_messages([{"role": "user", "content": user_input}])
    except Exception as e:
    print(f"Fehler bei der Verarbeitung: {e}")
    continue

    # Zeige die letzte Antwort des LLMs
    for msg in messages_out:
    if msg["role"] == "assistant":
    print(f"\nAssistant: {msg}")
    messages_out = []
    # Update Chatverlauf
    messages.extend(messages_out)
    finally:
    print("Räume Ressourcen auf...")
    await client.cleanup()

    Continue reading...

Compartilhe esta Página