Skip to content

[BUG] Tools parameters/arguements are not working #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AI3LabsX opened this issue Apr 14, 2025 · 7 comments
Closed

[BUG] Tools parameters/arguements are not working #60

AI3LabsX opened this issue Apr 14, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@AI3LabsX
Copy link

Bug Description

When
I use const tools = await client.getTools();
and
const bindLLM = llm.bind({
tools,
tool_choice: "auto",
});
it does not see tool arguments and always provide with empty arguments:
"tool_calls": [
{
"id": "call_Njw1orEyCrlaWWSjg3KTvdOE",
"type": "function",
"function": {
"name": "mcp__firecrawl__firecrawl_scrape",
"arguments": "{}"
}
}
]

Environment

  • OS:Win
@AI3LabsX AI3LabsX added the bug Something isn't working label Apr 14, 2025
@AI3LabsX
Copy link
Author

Code:

import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { ChatOpenAI } from "@langchain/openai";
import dotenv from "dotenv";
import util from "util";

dotenv.config();

(async () => {
    // Initialize the MCP client with server configuration for firecrawl.
    const client = new MultiServerMCPClient({
        // Global tool configuration options.
        throwOnLoadError: true,
        prefixToolNameWithServerName: true,
        additionalToolNamePrefix: "mcp",
        // MCP server configuration.
        mcpServers: {
            // Use a STDIO connection for the firecrawl server.
            firecrawl: {
                transport: "stdio",
                command: "npx",
                args: ["-y", "firecrawl-mcp"],
                env: {
                    FIRECRAWL_API_KEY: process.env.FIRECRAWL_API_KEY!,
                },
                // You can add additional options like timeout or restart configurations if needed.
            },
        },
    });

    try {
        // Load the tools from the Firecrawl MCP server.
        const tools = await client.getTools();
        // console.log("Loaded tools:", tools);
        console.log(util.inspect(tools[0], { showHidden: true, depth: null, colors: true }));

        // const result = await tools[0].invoke({ url: "https://github.com/mendableai/firecrawl-mcp-server", formats: ["markdown"], onlyMainContent: true });
        // console.log("Result:", result);
        const llm = new ChatOpenAI({
            modelName: "gpt-4o-mini",
        });

        const bindLLM = llm.bind({
            tools: tools,
            tool_choice: "auto",
        });
        const result = await bindLLM.invoke([
            // { role: "system", content: `Tool Prompt: ${JSON.stringify(tooldata)}` },
            {
                role: "system",
                content: `Use properties to get information about tool required arguments!`
            },
            {
                role: "user",
                content: "What is that page about: url: https://github.com/mendableai/firecrawl-mcp-server"
            }]);
        console.log("Result:", JSON.stringify(result.tool_calls, null, 2));

    } catch (error: any) {
        console.error("Error during agent invocation:", error);
        // For tool-specific errors, you might check error.name === "ToolException"
        if (error.name === "ToolException") {
            console.error("Tool execution failed:", error.message);
        }
    } finally {
        // Close the MCP client to clean up resources.
        await client.close();
    }
})();

results:
Result: [
{
"name": "mcp__firecrawl__firecrawl_scrape",
"args": {},
"type": "tool_call",
"id": "call_u0g1SHlRwjIdKz6bcdS5So3t"
}
]

In loog I can see properties are there, but bind can not pick them up.

@AI3LabsX
Copy link
Author

Just to mention, the same behaviour is with CreateReactAgent.

@AI3LabsX AI3LabsX changed the title [BUG] [BUG] Tools parameters/arguements are not working Apr 15, 2025
@postbird
Copy link

Same issue, I think the issue is caued by DynamicStructuredTool.

And I tried directly use DynamicStructuredTool to build the ReActAgent just like what this repo implemented, for example:

Image

And I pass this tool to ReAct agent like below:

Image

And I found that the LLM can not process the tool params, when I debug with the langsmith, I find that actually the params of the function calling are invalid.

Image

@AI3LabsX
Copy link
Author

AI3LabsX commented May 13, 2025

So I fixed my issues by down grading version a bit. Also am binding the whole getAllTools (maybe with some prefilteting step) and it works nicely.

@postbird
Copy link

So I fixed my issues by down grading version a bit. Also am binding the whole getAllTools (maybe with some prefilteting step) and it works nicely.

Actually, I found another way to solve this problem by forked this adapter project.

The only modification is that I added a new dependency @n8n/json-schema-to-zod, and converted the json-schema to zod schema like below before I passed the params to DynamicStructuredTool

Image

It worked well for me. And I also found that event we do not use DynamicStructuredTool to build the tool instance, we can directly use the tool() function , because we have got the zod-schema by this package.

And also, I found @n8n/json-schema-to-zod is the best package to solve this problem (I have tried several other packages).

Image

We can find that the params of the function calling are correct now.

@postbird
Copy link

So I fixed my issues by down grading version a bit. Also am binding the whole getAllTools (maybe with some prefilteting step) and it works nicely.

Actually, I found another way to solve this problem by forked this adapter project.

The only modification is that I added a new dependency @n8n/json-schema-to-zod, and converted the json-schema to zod schema like below before I passed the params to DynamicStructuredTool

Image

It worked well for me. And I also found that event we do not use DynamicStructuredTool to build the tool instance, we can directly use the tool() function , because we have got the zod-schema by this package.

And also, I found @n8n/json-schema-to-zod is the best package to solve this problem (I have tried several other packages).

Image

We can find that the params of the function calling are correct now.

Hi, @benjamincburns, thank you for providing the this adopter for developers to integrate the mcp servers easier. I'm wondering if there are any issues of DynamicStructuredTool with the version of langchain?

@benjamincburns
Copy link
Collaborator

benjamincburns commented May 13, 2025

This has been fixed as of v0.4.1. Please update to the latest versions of @langchain/core, @langchain/mcp-adapters and whichever chat model provider library you're using e.g. @langchain/openai.

If you're still experiencing issues after updating to latest versions of ALL of the above libraries, please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants