Repository navigation
Description
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.comwas 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
jasper-yl commentedon Dec 3, 2026
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:
gpt-4.1-mini(same versions as above): the captured LangChain request fails 3 of 3 withstrictomitted and passes 3 of 3 withstrict=False, with all 129anyOfpreserved.create_agentbinds tools itself, so the caller cannot passstricttobind_tools. A middleware that setsmodel_settings["strict"] = Falsedoes reach the request: with the 63-tool catalog, every tool is then sent withstrict: falseand 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:
powercontext-langchainthat binds the Server's MCP catalog non-strict (what the example'sbind_mcp_toolsdoes). It covers bothbind_toolsand agent use and touches only the PowerContext tools.PowerContextMiddleware. It only helpscreate_agentusers of the middleware, and it changesstrictfor 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 上的所有工具)。frf12 commentedon Dec 3, 2026
@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_toolsandcreate_agentusage, 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.
feat(langchain): add public helpers that bind MCP tools non-strict
jasper-yl commentedon Dec 3, 2026
@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
0f1da7d4ato 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, formodel.bind_tools([*mcp_tool_definitions(mcp_tools), *application_tools]).strict: falseis set per definition, so the application's other tools and their strict settings are sent as bound.McpToolDefinitionsMiddleware(tools): the same definitions forcreate_agent, applied per model call to the given tools by name; the agent still executes its own tools.bind_tools,create_agentsync (with an executed tool call) and async, using the full 63-tool catalog. They also check an application tool withoutstrictand one withstrict: true.Live check on api.openai.com
gpt-4.1-mini:create_agentwith the 63 tools loaded bylangchain-mcp-adaptersfails 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 恢复到之前的范围。frf12 commentedon Dec 3, 2026
@jasper-yl Keeping the helper, documentation, example, and regression tests together in #3002 is fine. No need to split it into a separate PR.