[BUG] Can't load external tools due to missing schemas #20

Closed
opened 2026-02-16 08:17:17 -05:00 by yindo · 4 comments
Owner

Originally created by @kikoncuo on GitHub (Apr 1, 2025).

Bug Description

When using tools built following the instructions everything works as expected, but when I want to use an NPM tool from a third party the schemas are not being parsed correctly.

Reproduction Steps

Import any external server. IE:
https://www.npmjs.com/package/time-mcp

IE:

// mcp_bug_report.js
// Minimal example to demonstrate potential schema loading issue with @langchain/mcp-adapters

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { loadMcpTools } from '@langchain/mcp-adapters';

async function demonstrateSchemaIssue() {
  // Configuration based on mcp.json for 'time-mcp'
  const serverName = 'time-mcp';
  const command = 'npx';
  const args = ['-y', 'time-mcp'];

  console.log(`[INFO] Setting up transport for ${serverName}...`);
  const transport = new StdioClientTransport({ command, args });

  console.log(`[INFO] Initializing base MCP client for ${serverName}...`);
  const client = new Client({
    name: 'mcp-bug-report-client',
    version: '1.0.0',
  });

  try {
    console.log(`[INFO] Connecting client to transport for ${serverName}...`);
    await client.connect(transport);
    console.log(`[INFO] Successfully connected to ${serverName}.`);

    console.log(`[INFO] Loading tools from ${serverName} using loadMcpTools...`);
    // Load tools using the adapter function
    const tools = await loadMcpTools(serverName, client);
    console.log(`[INFO] ${tools.length} tools loaded.`);

    console.log('\n[DEBUG] Inspecting loaded tools:');
    if (tools.length > 0) {
      tools.forEach((tool, index) => {
        console.log(`\n--- Tool ${index + 1} ---`);
        console.log(`Name: ${tool.name}`);
        console.log(`Description: ${tool.description}`);
        // The core issue: Inspect the 'schema' property
        console.log(`Schema: ${JSON.stringify(tool.schema, null, 2)}`);
        // Also log the entire tool object for context
        // console.log(`Full Tool Object: ${JSON.stringify(tool, null, 2)}`);
      });
      console.log('\n[EXPECTATION] The "Schema" output above should show a valid Zod schema object defining the tool\'s parameters.');
      console.log('[OBSERVATION] The "Schema" output might be undefined, null, or not a proper Zod schema.');
    } else {
      console.log('[WARN] No tools were found on the server.');
    }

  } catch (error) {
    console.error('\n[ERROR] An error occurred during the test:', error);
  } finally {
    if (client) {
      console.log('\n[INFO] Closing client connection...');
      await client.close();
      console.log('[INFO] Connection closed.');
    }
  }
}

demonstrateSchemaIssue();

Expected Behavior

Schemas to be loaded properly like when other tools load the servers IE:
See cline example:

Image

Actual Behavior

Schemas are broken and LLMs don't know how to call the tools

[DEBUG] Inspecting loaded tools:

--- Tool 1 ---
Name: current_time
Description: Get the current date and time.
Schema: {
  "_def": {
    "unknownKeys": "strict",
    "catchall": {
      "_def": {
        "typeName": "ZodNever"
      },
      "~standard": {
        "version": 1,
        "vendor": "zod"
      }
    },
    "typeName": "ZodObject"
  },
  "~standard": {
    "version": 1,
    "vendor": "zod"
  },
  "_cached": null
}

--- Tool 2 ---
Name: relative_time
Description: Get the relative time from now.
Schema: {
  "_def": {
    "unknownKeys": "strict",
    "catchall": {
      "_def": {
        "typeName": "ZodNever"
      },
      "~standard": {
        "version": 1,
        "vendor": "zod"
      }
    },
    "typeName": "ZodObject"
  },
  "~standard": {
    "version": 1,
    "vendor": "zod"
  },
  "_cached": null
}

--- Tool 3 ---
Name: days_in_month
Description: Get the number of days in a month. If no date is provided, get the number of days in the current month.
Schema: {
  "_def": {
    "unknownKeys": "strict",
    "catchall": {
      "_def": {
        "typeName": "ZodNever"
      },
      "~standard": {
        "version": 1,
        "vendor": "zod"
      }
    },
    "typeName": "ZodObject"
  },
  "~standard": {
    "version": 1,
    "vendor": "zod"
  },
  "_cached": null
}

--- Tool 4 ---
Name: get_timestamp
Description: Get the timestamp for the time.
Schema: {
  "_def": {
    "unknownKeys": "strict",
    "catchall": {
      "_def": {
        "typeName": "ZodNever"
      },
      "~standard": {
        "version": 1,
        "vendor": "zod"
      }
    },
    "typeName": "ZodObject"
  },
  "~standard": {
    "version": 1,
    "vendor": "zod"
  },
  "_cached": null
}
...

Environment

  • OS: Ubuntu 22.04
  • Node.js version: v22.14.0
  • Package version: 0.3.4

Additional Context

Add any other context about the problem here, such as:

Possible Solution

Review how the tools are loaded and how the schemas are parsed. I'll give it a go if someone can confirm

Originally created by @kikoncuo on GitHub (Apr 1, 2025). ## Bug Description When using tools built following the instructions everything works as expected, but when I want to use an NPM tool from a third party the schemas are not being parsed correctly. ## Reproduction Steps Import any external server. IE: https://www.npmjs.com/package/time-mcp IE: ``` // mcp_bug_report.js // Minimal example to demonstrate potential schema loading issue with @langchain/mcp-adapters import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; import { loadMcpTools } from '@langchain/mcp-adapters'; async function demonstrateSchemaIssue() { // Configuration based on mcp.json for 'time-mcp' const serverName = 'time-mcp'; const command = 'npx'; const args = ['-y', 'time-mcp']; console.log(`[INFO] Setting up transport for ${serverName}...`); const transport = new StdioClientTransport({ command, args }); console.log(`[INFO] Initializing base MCP client for ${serverName}...`); const client = new Client({ name: 'mcp-bug-report-client', version: '1.0.0', }); try { console.log(`[INFO] Connecting client to transport for ${serverName}...`); await client.connect(transport); console.log(`[INFO] Successfully connected to ${serverName}.`); console.log(`[INFO] Loading tools from ${serverName} using loadMcpTools...`); // Load tools using the adapter function const tools = await loadMcpTools(serverName, client); console.log(`[INFO] ${tools.length} tools loaded.`); console.log('\n[DEBUG] Inspecting loaded tools:'); if (tools.length > 0) { tools.forEach((tool, index) => { console.log(`\n--- Tool ${index + 1} ---`); console.log(`Name: ${tool.name}`); console.log(`Description: ${tool.description}`); // The core issue: Inspect the 'schema' property console.log(`Schema: ${JSON.stringify(tool.schema, null, 2)}`); // Also log the entire tool object for context // console.log(`Full Tool Object: ${JSON.stringify(tool, null, 2)}`); }); console.log('\n[EXPECTATION] The "Schema" output above should show a valid Zod schema object defining the tool\'s parameters.'); console.log('[OBSERVATION] The "Schema" output might be undefined, null, or not a proper Zod schema.'); } else { console.log('[WARN] No tools were found on the server.'); } } catch (error) { console.error('\n[ERROR] An error occurred during the test:', error); } finally { if (client) { console.log('\n[INFO] Closing client connection...'); await client.close(); console.log('[INFO] Connection closed.'); } } } demonstrateSchemaIssue(); ``` ## Expected Behavior Schemas to be loaded properly like when other tools load the servers IE: See cline example: ![Image](https://github.com/user-attachments/assets/30bcba37-da1c-4901-82b4-fdb1f00a3370) ## Actual Behavior Schemas are broken and LLMs don't know how to call the tools ``` [DEBUG] Inspecting loaded tools: --- Tool 1 --- Name: current_time Description: Get the current date and time. Schema: { "_def": { "unknownKeys": "strict", "catchall": { "_def": { "typeName": "ZodNever" }, "~standard": { "version": 1, "vendor": "zod" } }, "typeName": "ZodObject" }, "~standard": { "version": 1, "vendor": "zod" }, "_cached": null } --- Tool 2 --- Name: relative_time Description: Get the relative time from now. Schema: { "_def": { "unknownKeys": "strict", "catchall": { "_def": { "typeName": "ZodNever" }, "~standard": { "version": 1, "vendor": "zod" } }, "typeName": "ZodObject" }, "~standard": { "version": 1, "vendor": "zod" }, "_cached": null } --- Tool 3 --- Name: days_in_month Description: Get the number of days in a month. If no date is provided, get the number of days in the current month. Schema: { "_def": { "unknownKeys": "strict", "catchall": { "_def": { "typeName": "ZodNever" }, "~standard": { "version": 1, "vendor": "zod" } }, "typeName": "ZodObject" }, "~standard": { "version": 1, "vendor": "zod" }, "_cached": null } --- Tool 4 --- Name: get_timestamp Description: Get the timestamp for the time. Schema: { "_def": { "unknownKeys": "strict", "catchall": { "_def": { "typeName": "ZodNever" }, "~standard": { "version": 1, "vendor": "zod" } }, "typeName": "ZodObject" }, "~standard": { "version": 1, "vendor": "zod" }, "_cached": null } ... ``` ## Environment - OS: Ubuntu 22.04 - Node.js version: v22.14.0 - Package version: 0.3.4 ## Additional Context Add any other context about the problem here, such as: - Server implementation details: https://www.npmjs.com/package/time-mcp - Transport type (stdio, SSE): stdio ## Possible Solution Review how the tools are loaded and how the schemas are parsed. I'll give it a go if someone can confirm
yindo added the bug label 2026-02-16 08:17:17 -05:00
yindo closed this issue 2026-02-16 08:17:17 -05:00
Author
Owner

@kikoncuo commented on GitHub (Apr 2, 2025):

I can confirm the python version works as expected using that same MCP server

@kikoncuo commented on GitHub (Apr 2, 2025): I can confirm the python version works as expected using that same MCP server
Author
Owner

@benjamincburns commented on GitHub (Apr 3, 2025):

This appears to be a bug in the library that we're using to convert from JSONSchema to zod schema. I've created an issue in that project regarding this.

https://github.com/dmitryrechkin/json-schema-to-zod/issues/3

@benjamincburns commented on GitHub (Apr 3, 2025): This appears to be a bug in the library that we're using to convert from JSONSchema to zod schema. I've created an issue in that project regarding this. https://github.com/dmitryrechkin/json-schema-to-zod/issues/3
Author
Owner

@benjamincburns commented on GitHub (Apr 7, 2025):

The json-schema-to-zod package was always kind of an ugly hack. The better approach is to make it so LangChainJS can work directly w/ JSONSchema. With any luck I'm hoping to get this merged tomorrow: https://github.com/langchain-ai/langchainjs/pull/7973

@benjamincburns commented on GitHub (Apr 7, 2025): The `json-schema-to-zod` package was always kind of an ugly hack. The better approach is to make it so LangChainJS can work directly w/ JSONSchema. With any luck I'm hoping to get this merged tomorrow: https://github.com/langchain-ai/langchainjs/pull/7973
Author
Owner

@benjamincburns commented on GitHub (Apr 9, 2025):

Hi @kikoncuo please try v0.4.1. It should work much better now 😄

@benjamincburns commented on GitHub (Apr 9, 2025): Hi @kikoncuo please try v0.4.1. It should work much better now 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchainjs-mcp-adapters#20