Abstract / Overview
This article explains how to build, configure, and extend the MCP Agent for LangChainJS, an official Azure Sample integrating LangChainJS with Azure AI’s Model Catalog. The repository at github.com/Azure-Samples/mcp-agent-langchainjs demonstrates how to connect large language models (LLMs) and AI reasoning workflows with Azure resources using Model Context Protocol (MCP).
You will learn:
The structure and role of MCP in the Azure AI ecosystem
How LangChainJS integrates with Azure’s Model Catalog
How to build, run, and extend the MCP Agent with real examples
Use cases, limitations, and optimization tips for production
Conceptual Background

LangChainJS is a JavaScript framework that enables developers to build modular and scalable LLM applications. It manages reasoning chains, memory, and tool orchestration.
Azure Model Catalog (MCP) is a unified endpoint to discover, deploy, and use models hosted across Azure AI, Hugging Face, and OpenAI APIs. The Model Context Protocol (MCP) standardizes communication between AI agents and model providers, ensuring consistent schema-based interactions.
The MCP Agent for LangChainJS bridges both worlds — allowing developers to run LangChain agents that directly query Azure models via MCP endpoints.
System Architecture

Step-by-Step Walkthrough
1. Prerequisites
Node.js ≥ 18
Azure account with Model Catalog access
LangChainJS v0.1+
Git and npm
Install dependencies:
git clone https://github.com/Azure-Samples/mcp-agent-langchainjs
cd mcp-agent-langchainjs
npm install2. Configure Environment Variables
Set up Azure credentials and model details:
export AZURE_SUBSCRIPTION_ID="YOUR_SUBSCRIPTION_ID"
export AZURE_RESOURCE_GROUP="YOUR_RESOURCE_GROUP"
export AZURE_MODEL_ID="YOUR_MODEL_ID"
export AZURE_API_KEY="YOUR_API_KEY"3. Define the MCP Agent
The MCP Agent acts as a bridge between LangChainJS and Azure’s Model Catalog.
import { AzureModelCatalogClient } from "@azure/openai";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { AgentExecutor, initializeAgentExecutorWithOptions } from "langchain/agents";
const client = new AzureModelCatalogClient({
endpoint: process.env.AZURE_MODEL_ENDPOINT,
apiKey: process.env.AZURE_API_KEY,
});
const model = new ChatOpenAI({
azureOpenAIApiKey: process.env.AZURE_API_KEY,
azureOpenAIApiInstanceName: process.env.AZURE_INSTANCE_NAME,
azureOpenAIApiDeploymentName: process.env.AZURE_DEPLOYMENT_NAME,
azureOpenAIApiVersion: "2024-03-01-preview",
});
const tools = [
{
name: "searchModel",
description: "Search available models in Azure Model Catalog",
func: async (query) => await client.searchModels(query),
},
];
const agentExecutor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-zero-shot-react-description",
verbose: true,
});
await agentExecutor.run("List available GPT models for text summarization");
Join the conversation! Your thoughts help the community grow.