Skip to main content
LangChainMCPAgent connects LangChain chat models and callbacks to MCP tools. Import it from @mcp-use/agent/langchain.

When to use LangChainMCPAgent

Use LangChainMCPAgent when you need at least one of these capabilities:
  • an existing LangChain chat model or custom LangChain tool;
  • Zod structured-output conversion after an agent run;
  • LangChain StreamEvent output or prettyStreamEvents();
  • Server Manager for on-demand access to one MCP server’s tools; or
  • LangChain callbacks, Langfuse tracing, metadata, and tags.

Install LangChainMCPAgent

Install the agent package, LangChain core packages, and the provider package for your model.
Add zod for structured output. Add langfuse and langfuse-langchain for built-in Langfuse tracing.

Run a LangChain agent

Set OPENAI_API_KEY, then run:
A successful run prints a text answer based on package.json. LangChainMCPAgent defaults to 5 model-call steps.
LangChainMCPAgent.close() closes its MCP client even when you supplied that client. Do not share the client with work that must continue after the agent closes.

Next steps

Structured output

Convert final text into validated Zod data.

Server Manager

Load one server’s tools on demand.

Observability

Trace runs with Langfuse or custom callbacks.