Repository navigation
Conversation
…ses API ChatOpenAI(use_responses_api=True).bind_tools() leaves strict out of every function tool by default. The Responses API then applies strict mode, and a request that carries the full PowerContext MCP catalog can fail. Document bind_tools(..., strict=False) in both locales, add a runnable example that binds the catalog of a running Server and executes the tools the model calls, and cover the outgoing request with a regression test. Closes oceanbase#2999 Co-Authored-By: Claude <noreply@anthropic.com>
jasper-yl
requested review from
PsiACE,
hidb4ai and
zhanghuidinah
as code owners
December 3, 2026 08:24
mcp_tool_definitions() returns function tool definitions that set strict to false themselves and keep each input schema, so they can be bound next to the application's own tools without changing those. McpToolDefinitionsMiddleware applies the same definitions to the tools create_agent binds itself, while the agent still executes the tools it was created with. Cover both paths with request-capture tests, document them in both locales, and switch the example to the helper. Refs oceanbase#2999 Co-Authored-By: Claude <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue or RFC does this PR close?
Closes #2999.
Rationale for this change
Follow-up to #2996 / #2998 for the generic MCP-to-LangChain binding path.
ChatOpenAI(use_responses_api=True).bind_tools(tools)usesstrict=Noneby default and leavesstrictout of every function tool. The Responses API applies strict mode to a function tool that omits the field, and a request that carries the full PowerContext MCP catalog (63 tools, 129anyOf) then fails. Sending the tools withstrict: falseand unchanged schemas makes the request complete.create_agentbinds its tools itself, so a caller cannot passstrictthere. Per the decision in #2999, this PR adds a supported entry point inpowercontext-langchainfor both paths, scoped to the tools the caller passes.What changes are included in this PR?
powercontext_langchain.mcp_tool_definitions(tools): returns function tool definitions that setstrict: falsethemselves and keep each input schema. It accepts MCPToolobjects (aslist_tools()returns them) and LangChainBaseTools.model.bind_tools([*mcp_tool_definitions(mcp_tools), *application_tools])leaves the application's tools and theirstrictsettings as bound.powercontext_langchain.McpToolDefinitionsMiddleware(tools): forcreate_agent. On each model call it replaces the given tools, by name, with those definitions in theModelRequest. The agent still executes the tools it was created with; tools that were not given are unchanged.tests/langchain_middleware/test_mcp_tools.py: request-capture regressions through the realChatOpenAIinterface (httpx.MockTransport) with the full catalog fromscripts/mcp_catalog.py, forbind_tools,create_agent(sync, including one executed tool call and the second request) andcreate_agent(async). Each checksstrict: falseandparameters == inputSchemafor every MCP tool; thebind_toolsand sync agent tests also check that application tools are sent as bound (one withoutstrict, and forbind_toolsone withstrict: true).docs/{en,zh}/docs/integrations/langchain.md,integrations/langchain/README.md: a section on binding the Server's MCP tools with the two helpers.integrations/langchain/examples/bind_mcp_tools.pyandexamples/README.md: a runnable example that lists the catalog of a running Server over MCP, binds it throughmcp_tool_definitions, and executes the MCP tools the model calls.tests/test_langchain_mcp_binding.pycovers its binding function.PowerContextMiddleware, the LangGraph adapter and the MCP schemas are unchanged.Are there any user-facing changes?
Two new public names in
powercontext-langchain(mcp_tool_definitions,McpToolDefinitionsMiddleware), documentation and an example. No change to existing behavior.How was this change tested?
Python 3.12,
langchain-openai==1.6.0,langchain-core==1.8.1,langchain==1.5.0,openai==3.42.1. Provider:gpt-4.1-minion api.openai.com, which the issue had not covered.strictomittedbind_tools(63 tools, 129anyOf), replayed withstream: true,store: falseserver_error)pong). Measured withbind_tools(..., strict=False)before the helper existed; the helper sends the same per-toolstrict: false/mcp/) and the real providermcp_tool_definitionscreate_agentwith tools loaded bylangchain-mcp-adaptersfrom the real Server, real providerMcpToolDefinitionsMiddleware; the model calls an MCP tool, the agent executes it and answers from the resultuv run pytest tests/langchain_middleware tests/test_langchain_mcp_binding.py -q: 15 passed, 1 skipped. All four binding tests fail when"strict": Falseis removed from the helper.make check: passes.make docs-test: passes.Not covered: Azure OpenAI (not re-run; see the issue),
McpToolDefinitionsMiddlewarecombined withPowerContextMiddlewarein one agent, and non-OpenAI chat models.AI usage statement
Investigated, written and verified with Claude Code (Claude Fable 5), reviewed by the author.
中文摘要:
ChatOpenAI(use_responses_api=True)默认不发送strict字段,Responses API 会按 strict 模式处理,带完整 PowerContext MCP 工具目录的请求可能失败。本 PR 按 #2999 的结论在powercontext-langchain中提供两个公开入口:mcp_tool_definitions(用于bind_tools)和McpToolDefinitionsMiddleware(用于create_agent),只作用于调用方传入的工具,schema 不变,应用的其他工具及其strict设置不受影响。附带截获请求的回归测试、中英文文档和可运行示例。在 api.openai.com 的gpt-4.1-mini上验证:不使用时失败,使用后通过。🤖 Generated with Claude Code