开源LangChain Releases·2026年9月5日

LangChain发布 1.4.0a1预发布版,将MCP适配器并入主包并简化elicitation流程

新版本把MCP工具转换逻辑从langchain-mcp-adapters移植进langchain.mcp命名空间,要求FastMCP 4.0.0b4,并统一协议版本处理,同时收紧HITL与错误处理。

AI解读:LangChain 1.4.0a1是一个预发布版本,核心变化是把MCP(模型上下文协议)适配能力从独立的langchain-mcp-adapters仓库合并到主语言包里,新增langchain.mcp命名空间和MCPAdapter。这意味着使用LangChain的开发者在接入MCP服务器时少装一个包、少处理一层兼容问题。与此同时,新版本重构了elicitation(模型向人类或工具请求补充信息)的机制,改用LangGraph中断(interrupt)来处理这类请求,而不是轮询等待,并且把协议新旧版本(protocol eras)统一到一个适配器里。其他还有大量中间件修复,比如人机交互(HITL)审批不再静默失败、PII中间件在流式输出时即时编辑、工具重试只处理可重试异常。对普通用户来说,如果当前稳定版用得正常,不需要立即升级;但对在LangChain里做多服务器MCP集成、需要复杂人工审批或敏感信息过滤的开发者,这个预发布版值得在测试环境里验证,尤其是关注你是否依赖FastMCP 4.0.0b4及以上版本,以及你的Pydantic是否符合MCP要求。

LangChain发布 1.4.0a1预发布版(release),这是该系列的初始alpha版本。核心变化是将MCP(模型上下文协议)工具转换逻辑从独立的langchain-mcp-adapters库迁移进主包的langchain.mcp命名空间,并提供MCPAdapter。版本要求FastMCP 4.0.0b4以上(对应mcp extra),测试中会跳过Pydantic旧版本不支持的MCP用例。

MCP适配重构:统一协议版本与elicitation中断机制

1.4.0a1的提交记录显示,LangChain将MCP适配器代码从langchain-mcp-adapters移植到主库(feat(langchain): port MCP tool conversion from `langchain-mcp-adapters`),并引入langchain.mcp命名空间(feat(langchain): langchain.mcp namespace, `MCPAdapter`)。测试覆盖多服务器场景下新旧两种MCP协议版本(protocol eras),并通过单一适配器统一处理。

此外,elicitation(模型主动请求额外输入)机制被改变:原先的MCP轮询方式被废弃(feat(langchain): refuse MCP continuation rounds instead of polling),新实现通过LangGraph中断(interrupt)响应elicitation请求(feat(langchain): answer MCP elicitation with a LangGraph interrupt)。elicitation相关类型从langchain.mcp中移出,每种模式、每个动作各自维护独立的请求/响应类型,并用ELICITATION_INTERRUPT_TYPE作为判别器。

  • MCPAdapter不再提供aclose方法(refactor(langchain): drop `MCPAdapter.aclose`)。
  • 对FastMCP的两个私有依赖改为显式失败(fix(langchain): make the two FastMCP-private dependencies fail loudly)。
  • elicitation调用在会话失效时有保护,重试循环也受限(fix(langchain): guard MCP elicitation calls against a dying session)。

中间件与错误处理修复

同期记录包含一系列中间件修复。HumanInTheLoopMiddleware(HITL)审批不再静默失败(fix(langchain): stop HITL approval gates from silently failing open),并支持自定义拒绝原因(fix(langchain): frame custom HITL rejection reasons)。PIIMiddleware在流式输出时即时编辑内容(feat(langchain): redact streamed PII in flight on `PIIMiddleware`),并保留内容块结构(fix(langchain): preserve content-block shape in PIIMiddleware redaction)。

ToolRetryMiddleware只重试可重试异常(fix(langchain): only retry retryable exceptions in `ToolRetryMiddleware`),并可传递中断(feat(langchain): propagate interrupts through ToolRetryMiddleware)。SummarizationMiddleware在摘要失败时保留历史(fix(langchain): preserve history on `SummarizationMiddleware` summary failure)。

  • 结构化输出响应新增错误处理(fix(langchain): handle malformed structured-output responses)。
  • init_chat_model新增LangSmith provider(feat(langchain): add LangSmith provider to `init_chat_model`)。
  • 模型中间件控制流在链式调用中正确传播(fix(langchain): propagate model middleware control flow)。

信息来源

LangChain Releases原始来源