Skip to content

bug(langchain): Responses can fail with the full MCP catalog when strict is omitted #2999

Done

Description

@frf12

Describe the bug

Follow-up to #2996, separate from the DSH configuration change in #2998.

When a caller manually binds PowerContext's full MCP catalog to ChatOpenAI(use_responses_api=True), LangChain's default strict=None leaves strict out of the outgoing function tools. Replaying this captured request against Azure OpenAI gpt-5.2 failed with model_error / response.failed. Adding only strict:false to each function tool made the same request complete successfully with pong.

This concerns the generic MCP-to-LangChain binding path. The PowerContext LangChain middleware does not automatically register this catalog. The project's separate LangGraph three-tool integration passed the same provider check with strict omitted.

Steps to reproduce

Use the full catalog at PowerContext commit 9e40f8996be538970922121fb82168f825a8cf0c (also unchanged at #2998 head 12fcddc8df27f2dcf7c0ebfa7a97be346bb27b47). The repository's scripts/mcp_catalog.py enables optional Handoff reporting, yielding 63 tools with 129 anyOf occurrences; a Server with different feature settings may expose fewer tools.

The binding setup is:

import os
from copy import deepcopy

from langchain_openai import ChatOpenAI
from mcp_catalog import server_mcp_tools

tools = [
    {
        "name": tool.name,
        "description": tool.description or "",
        "parameters": tool.inputSchema,
    }
    for tool in server_mcp_tools()
]

# Set OPENAI_API_KEY and OPENAI_BASE_URL for the intended compatible provider.
model = ChatOpenAI(
    model="gpt-5.2",
    base_url=os.environ["OPENAI_BASE_URL"],
    use_responses_api=True,
    max_retries=0,
)
default_binding = model.bind_tools(deepcopy(tools))
explicit_non_strict = model.bind_tools(deepcopy(tools), strict=False)

Run from the repository root with PYTHONPATH=src:scripts and the dependencies below. Use a synthetic prompt such as Reply exactly pong. Do not call any tools.

The verified procedure captured the outgoing JSON from the real LangChain binding with httpx.MockTransport, then replayed it to the real provider with stream:true and store:false. The provider control was the identical captured body with only strict:false added to its 63 tools. No tools were invoked, and no live MCP connection or complete agent workflow was exercised.

Actual and expected behavior

Request Actual terminal result
Full catalog, strict omitted HTTP 200 stream containing model_error and response.failed, no answer
Identical request, all 63 tools set to strict:false response.completed, answer pong

The original parameters and all 129 anyOf occurrences were preserved in the successful control. HTTP 200 alone is not a successful Responses result.

Users choosing this binding path should have a documented way to preserve the MCP schemas and generate a working request. This does not establish that every anyOf, tool subset, model, or provider fails when strict is omitted.

Environment

  • Python 3.12.7
  • langchain-openai==1.6.0, langchain-core==1.8.1, openai==3.42.1
  • Provider verification: Azure OpenAI gpt-5.2, streaming Responses API
  • Official api.openai.com was not tested in this follow-up

Suggested scope

  • Add matching English/Chinese guidance and a runnable example for the full MCP catalog + LangChain Responses path, using bind_tools(..., strict=False).
  • Add a focused regression that captures the outgoing request through the real LangChain interface and checks explicit false while preserving the supplied schemas.
  • Keep the generic MCP binding distinct from the PowerContext middleware and the LangGraph three-tool adapter. There is no demonstrated need to change those adapters or remove unions from the shared MCP schemas for this fix.

@jasper-yl, would you be willing to take this LangChain follow-up in a separate PR? Your investigation in #2996 is directly relevant; the configuration entry point here is LangChain's bind_tools rather than DSH's provider compatibility switch.

Activity

  1. added
    bug
    documentation
    on Dec 3, 2026
  2. moved this from Todo to In progress in PowerContexton Dec 3, 2026
  3. jasper-yl commented on Dec 3, 2026

    @jasper-yl
    Contributor

    Thanks for the invitation — I'll take this. #3002 has the en/zh guidance, a runnable example and the request-capture regression, and follows the scope above.

    Two findings while preparing it:

    • The failure also reproduces on api.openai.com with gpt-4.1-mini (same versions as above): the captured LangChain request fails 3 of 3 with strict omitted and passes 3 of 3 with strict=False, with all 129 anyOf preserved.
    • create_agent binds tools itself, so the caller cannot pass strict to bind_tools. A middleware that sets model_settings["strict"] = False does reach the request: with the 63-tool catalog, every tool is then sent with strict: false and unchanged schemas (request capture only, not run against a provider).

    One scope question: would you want a supported entry point instead of documentation only? Two options:

    1. A public helper in powercontext-langchain that binds the Server's MCP catalog non-strict (what the example's bind_mcp_tools does). It covers both bind_tools and agent use and touches only the PowerContext tools.
    2. An opt-in switch on PowerContextMiddleware. It only helps create_agent users of the middleware, and it changes strict for every tool on the agent, including the application's own.

    #3002 stays within the documented scope; I can do either of these as a follow-up if you want it.

    中文:#3002 已按上述范围提交。补充两点:api.openai.com 的 gpt-4.1-mini 上同样复现;create_agent 路径下调用方无法给 bind_tools 传 strict,但 middleware 设置 model_settings 可以生效(仅截获请求验证)。想确认是否需要在文档之外提供正式入口:在 powercontext-langchain 中提供绑定 MCP 目录的公开函数,或给 PowerContextMiddleware 加可选开关(后者只覆盖 create_agent 用户,且会影响 agent 上的所有工具)。

  4. frf12 commented on Dec 3, 2026

    @frf12
    MemberAuthor

    @jasper-yl, let's go with option 1: a supported public helper in powercontext-langchain, scoped to PowerContext's MCP tools.

    Please preserve the supplied schemas and leave the application's other tools and their strict settings unchanged. Cover both direct bind_tools and create_agent usage, with focused request-capture regressions for those paths.

    Please implement this in a separate follow-up PR linked here; #3002 can keep its current documentation, example, and test scope. Thanks for picking this up.

  5. jasper-yl commented on Dec 3, 2026

    @jasper-yl
    Contributor

    @frf12 Done as option 1. One deviation from your note: I pushed the helper onto #3002 instead of opening a separate PR. #3002 had not been reviewed yet, the helper replaces the documentation it added (same section, same example), and a second PR would have been stacked on it and shown both diffs until #3002 merged. If you prefer the split, say so and I'll move commit 0f1da7d4a to its own PR and restore #3002 to its previous scope.

    What #3002 now contains:

    • mcp_tool_definitions(tools): non-strict function tool definitions with the supplied schemas, for model.bind_tools([*mcp_tool_definitions(mcp_tools), *application_tools]). strict: false is set per definition, so the application's other tools and their strict settings are sent as bound.
    • McpToolDefinitionsMiddleware(tools): the same definitions for create_agent, applied per model call to the given tools by name; the agent still executes its own tools.
    • Request-capture regressions for bind_tools, create_agent sync (with an executed tool call) and async, using the full 63-tool catalog. They also check an application tool without strict and one with strict: true.

    Live check on api.openai.com gpt-4.1-mini: create_agent with the 63 tools loaded by langchain-mcp-adapters fails 2 of 2 without the middleware and passes 2 of 2 with it, including an executed MCP tool call.

    中文:已按方案 1 实现。与你的说明有一处不同:我把公开入口直接推到了 #3002,没有另开 PR,因为 #3002 尚未评审,新入口替换的正是它新增的那段文档和示例,另开的 PR 在 #3002 合并前会叠在它上面。如果你更希望拆开,我会把提交 0f1da7d4a 移到单独的 PR,并把 #3002 恢复到之前的范围。

  6. frf12 commented on Dec 3, 2026

    @frf12
    MemberAuthor

    @jasper-yl Keeping the helper, documentation, example, and regression tests together in #3002 is fine. No need to split it into a separate PR.

  7. moved this from In progress to Done in PowerContexton Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentation

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions