MCP Agent Langchainjs 标志

MCP Agent Langchainjs

组织
Azure-Samples

Serverless AI agent using LangChain.js and Model Context Protocol (MCP) integration to order burgers from a burger restaurant

发布者Azure-Samples
代码仓库mcp-agent-langchainjs
语言TypeScript
复刻数
97
星标数
203
可用工具
0
传输类型stdio
许可协议MIT
链接
  • 将工具接入 AI 工作流

    MCP Agent Langchainjs 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 203 个星标和 97 个复刻。

AI Agent with MCP tools using LangChain.js

Open in Codespaces Join Microsoft Foundry Community Discord Deployment time Build Status dev.to blog post walkthrough Node version TypeScript License

⭐ If you like this sample, star it on GitHub — it helps a lot!

Overview • Architecture • Getting started • Deploy to Azure • Run locally • MCP tools • Resources

Animation showing the agent in action

[!IMPORTANT] 👉 Follow the full-length workshop to learn how we built this sample.

Overview

This project demonstrates how to build AI agents that can interact with real-world APIs using the Model Context Protocol (MCP). It features a complete burger ordering system with a serverless API, web interfaces, and an MCP server that enables AI agents to browse menus, place orders, and track order status. The agent uses LangChain.js to handle LLM reasoning and tool calling. The system consists of multiple interconnected services, as detailed in the Architecture section below.

The system is hosted on Azure Static Web Apps (web apps) and Azure Functions (API and MCP servers), with Azure Cosmos DB for NoSQL for data storage. You can use it as a starting point for building your own AI agents.

[!TIP] You can test this application locally without deployment needed or any cloud costs. The MCP server also works with popular AI tools like GitHub Copilot, Claude, and other MCP-compatible clients. Follow the instructions in the Local Development section to get started.

Key features

  • LangChain.js agent with tool calling via MCP (Streamable HTTP transport)
  • Multi-service, end‑to‑end architecture (web UIs, APIs, MCP server)
  • User authentication with sessions history
  • 100% serverless architecture, for cost-effective scaling
  • Single-command deployment using Infrastructure as Code (IaC)

Architecture

Building AI applications can be complex and time-consuming, but using LangChain.js and Azure serverless technologies allows to greatly simplify the process. This application is a AI agent that can be access through different interfaces (web app, CLI) and that can call tools through MCP to interact with a burger ordering API.

Architecture diagram

The application is made from these main components:

ComponentFolderPurpose
Agent Web Apppackages/agent-webappChat interface + conversation rendering
Agent APIpackages/agent-apiLangChain.js agent + chat state + MCP client
Burger APIpackages/burger-apiCore burger & order management web API
Burger MCP Serverpackages/burger-mcpExposes burger API as MCP tools
Burger Web Apppackages/burger-webappLive orders visualization
InfrastructureinfraBicep templates (IaC)

Additionally, these optional and support components are included:

ComponentFolderPurpose
Beer MCP Serverpackages/beer-mcpAI-powered beer recommendations via hybrid RAG
Agent CLIpackages/agent-cliCommand-line interface LangChain.js agent and MCP client
Data generationpackages/burger-dataScripts to (re)generate burgers data & images

Getting started

There are multiple ways to get started with this project. The quickest way is to use GitHub Codespaces that provides a preconfigured environment for you. Alternatively, you can set up your local environment following the instructions below.

You can run this project directly in your browser by using GitHub Codespaces, which will open a web-based VS Code:

Open in GitHub Codespaces

A similar option to Codespaces is VS Code Dev Containers, that will open the project in your local VS Code instance using the Dev Containers extension.

You will also need to have Docker installed on your machine to run the container.

Open in Dev Containers

You need to install following tools to work on your local machine:

  • Node.js LTS
  • Azure Developer CLI 1.19+
  • Git
  • PowerShell 7+ (for Windows users only)
    • Important: Ensure you can run pwsh.exe from a PowerShell command. If this fails, you likely need to upgrade PowerShell.
    • Instead of Powershell, you can also use Git Bash or WSL to run the Azure Developer CLI commands.

Then you can get the project code:

  1. Fork the project to create your own copy of this repository.

  2. On your forked repository, select the Code button, then the Local tab, and copy the URL of your forked repository.

    Screenshot showing how to copy the repository URL

  3. Open a terminal and run this command to clone the repo: git clone <your-repo-url>

Deploy to Azure

Prerequisites

Deploy with Azure Developer CLI

  1. Open a terminal and navigate to the root of the project
  2. Authenticate with Azure by running azd auth login
  3. Run azd up to deploy the application to Azure. This will provision Azure resources and deploy all services
    • You will be prompted to select a base location for the resources
    • The deployment process will take a few minutes

Once deployment is complete, you'll see the URLs of all deployed services in the terminal.

[!IMPORTANT] If you're using an Azure for Students or Free Trial account that you just created, you need to run the following command before running azd up or else the deployment will fail:

sh
azd env set AZURE_OPENAI_MODEL_CAPACITY 1

This ensures that the resources deployed will fit within the free tier limits. This limitations reduce the capacity for AI models usage, so you'll also have to provide another OpenAI endpoint to use the application properly. To do that, use the following commands to set the OpenAI endpoint, API key and model you want to use:

sh
azd env set AZURE_OPENAI_ALT_ENDPOINT <your_openai_endpoint>
azd env set AZURE_OPENAI_API_KEY <your_openai_api_key>
azd env set AZURE_OPENAI_MODEL <your_openai_model>

You can for example use the free GitHub Models for this, or any other OpenAI compatible endpoint.

Cost estimation

Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can use the Azure pricing calculator with pre-configured estimations to get an idea of the costs: Azure Pricing Calculator.

Clean up resources

To clean up all the Azure resources created by this sample:

bash
azd down --purge

Use Ollama for local development

If you have a machine with enough resources, you can run this sample entirely locally without using any cloud resources. To do that, you first have to install Ollama and then run the following commands to download a model on your machine:

bash
ollama pull qwen3:8b

[!TIP] If you have a powerful machine with enough memory, you can try using gpt-oss:20b instead to get better results.

After that create a .env file in the root of the project with the following content:

env
AZURE_OPENAI_API_ENDPOINT="http://localhost:11434/v1"
AZURE_OPENAI_MODEL="qwen3:8b"
AZURE_OPENAI_API_KEY="__not_used__"

You can now continue to the run locally section to start the application.

[!NOTE] Local models may not work as well as cloud-hosted models, and may even fail to respond for some complex requests. This is a limitation of the local models and not of the application itself.

Run locally

After setting up your environment and either provisioned the Azure resources or set up Ollama, you can run the entire application locally:

bash
# Install dependencies for all services
npm install

# Start all services locally
npm start

Starting the different services may take some time, you need to wait until you see the following message in the terminal: 🚀 All services ready 🚀

This will start:

[!NOTE] When running locally without having deployed the application, the servers will use in-memory storage, so any data will be lost when you stop the servers. After a successful deployment, the servers will use Azure Cosmos DB for persistent storage.

You can then open the Agent web app and ask things like:

  • What spicy burgers do you have?
  • Order two Classic Cheeseburgers with extra bacon.
  • Show my recent orders

The agent will decide which MCP tool(s) to call, then come up with a response.

Available scripts

This project uses npm workspaces to manage multiple packages in a single repository. You can run scripts from the root folder that will apply to all packages, or you can run scripts for individual packages as indicated in their respective README files.

Common scripts (run from repo root):

ActionCommand
Start everythingnpm start
Build allnpm run build
Lintnpm run lint
Fix lintnpm run lint:fix
Formatnpm run format

MCP tools

The Burger MCP server provides these tools for AI agents:

Tool NameDescription
get_burgersGet a list of all burgers in the menu
get_burger_by_idGet a specific burger by its ID
get_toppingsGet a list of all toppings in the menu
get_topping_by_idGet a specific topping by its ID
get_topping_categoriesGet a list of all topping categories
get_ordersGet a list of all orders in the system
get_order_by_idGet a specific order by its ID
place_orderPlace a new order with burgers (requires userId, optional nickname)
delete_order_by_idCancel an order if it has not yet been started (status must be pending, requires userId)

Testing the MCP Server

Using the MCP Inspector

You can test the MCP server using the MCP Inspector:

  1. Install and start MCP Inspector:

    bash
    npx -y @modelcontextprotocol/inspector
  2. In your browser, open the MCP Inspector (the URL will be shown in the terminal)

  3. Configure the connection:

    • Transport: Streamable HTTP
    • URL: http://localhost:3000/mcp
  4. Click Connect and explore the available tools

Using GitHub Copilot

To use the MCP server in local mode with GitHub Copilot, create a local .vscode/mcp.json configuration file in your project root:

json
{
  "servers": {
    "burger-mcp": {
      "type": "stdio",
      "command": "npm",
      "args": ["run", "start:local", "--workspace=burger-mcp"]
    }
  }
}

If you open that file

Then, you can use GitHub Copilot in agent mode to interact with the MCP server. For example, you can ask questions like "What burgers are available?" or "Place an order for a vegan burger" and Copilot will use the MCP server to provide answers or perform actions.

[!TIP] Copilot models can behave differently regarding tools usage, so if you don't see it calling the burger-mcp tools, you can explicitly mention using the Bruger MCP server by adding #burger-mcp in your prompt.

Resources

Here are some resources to learn more about the technologies used in this project:

You can also find more Azure AI samples here.

Troubleshooting

If you encounter issues while running or deploying this sample:

  1. Dependencies: Ensure all required tools are installed and up to date
  2. Ports: Make sure required ports (3000, 4280, 5173, 5174, 7071, 7072) are not in use
  3. Azure Developer CLI: Verify you're authenticated with azd auth login
  4. Node.js version: Ensure you're using Node.js 22 or higher

For more detailed troubleshooting, check the individual README files in each service directory.

FAQ

What is MCP (Model Context Protocol)?

MCP is a protocol that enables AI agents to interact with external tools and APIs in a standardized way. It provides a common interface for tools, making it easier to integrate different services and capabilities into AI agents. Learn more at modelcontextprotocol.io.

How does this project differ from other AI agent samples?

This sample focuses on MCP integration with LangChain.js in a serverless architecture. Unlike standalone agent examples, this project demonstrates:

  • Multi-service architecture (web UIs, APIs, MCP server)
  • Production-ready deployment on Azure
  • Real-world use case (burger ordering system)
  • Integration with popular AI tools (GitHub Copilot, Claude)

Which LLM providers are supported?

The agent supports any OpenAI-compatible endpoint:

  • Azure OpenAI (default when deployed to Azure)
  • GitHub Models (free alternative)
  • Ollama (local development)
  • Any other OpenAI-compatible API (set via AZURE_OPENAI_API_ENDPOINT)

What's the difference between local and cloud deployment?

Local development:

  • Uses in-memory storage (data lost on restart)
  • No cloud costs
  • Requires local setup (Node.js, Docker)
  • Perfect for testing and development

Azure deployment:

  • Uses Azure Cosmos DB for persistent storage
  • Production-ready with authentication
  • Single-command deployment with azd up
  • Scalable and cost-effective serverless architecture

How does the MCP server work?

The Burger MCP server exposes burger API operations as MCP tools:

  • It translates API calls into MCP tool definitions
  • AI agents can discover and call these tools automatically
  • Uses Streamable HTTP transport for communication
  • Works with MCP-compatible clients (Copilot, Claude, etc.)

Can I use this MCP server with other AI tools?

Yes! The MCP server is compatible with:

  • GitHub Copilot (agent mode) - via .vscode/mcp.json config
  • Claude Desktop - via MCP client configuration
  • MCP Inspector - for testing and debugging
  • Any MCP-compatible client

What are the prerequisites for deployment?

  • Azure account with Microsoft.Authorization/roleAssignments/write permissions
  • Azure Developer CLI (azd) 1.19+
  • Node.js 22+ LTS
  • Git for cloning the repository

How do I customize the MCP tools?

You can extend the MCP server by:

  1. Adding new tool definitions in packages/burger-mcp
  2. Implementing corresponding API endpoints in packages/burger-api
  3. Updating the tool schema to expose new operations
  4. Testing with MCP Inspector before deployment

Why am I getting "model capacity" errors on Azure?

If using Azure for Students or Free Trial, run:

bash
azd env set AZURE_OPENAI_MODEL_CAPACITY 1

This ensures resources fit within free tier limits. You may also need to provide an alternative OpenAI endpoint.

Where can I get help?

Built for AI Agents

This project has been optimized for use with AI agents like GitHub Copilot. This includes:

  • Built-in context engineering provided with AGENTS.md files to help AI agents understand and extend the codebase.
  • Reusable prompts for common tasks.
  • Custom instructions tailored for each service of the project.
  • Custom Codebase Explorer chat mode for Copilot, to help you explore and understand the codebase.

To learn how to set up and use GitHub Copilot with this repository, check out the docs/copilot.md guide.

Getting Help

If you get stuck or have any questions about building AI apps, join:

Microsoft Foundry Discord

If you have product feedback or errors while building visit:

Microsoft Foundry Developer Forum

将 MCP Agent Langchainjs MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 MCP Agent Langchainjs 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 MCP Agent Langchainjs 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 MCP Agent Langchainjs MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "mcp-agent-langchainjs": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 MCP Agent Langchainjs MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 MCP Agent Langchainjs MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 MCP Agent Langchainjs 帮我完成这项任务吗?
MCP Agent Langchainjs
当然,我看过了。
以下是我使用 MCP Agent Langchainjs 得到的结果。

常见问题

MCP Agent Langchainjs MCP 服务器有什么用途?

MCP Agent Langchainjs 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 MCP Agent Langchainjs MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 MCP Agent Langchainjs。

为什么在 TypingMind 中使用 MCP Agent Langchainjs MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 MCP Agent Langchainjs 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 MCP Agent Langchainjs MCP 连接到 TypingMind?

MCP Agent Langchainjs 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

MCP Agent Langchainjs MCP 在 TypingMind 中提供哪些工具?

MCP Agent Langchainjs 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 MCP Agent Langchainjs MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 MCP Agent Langchainjs 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇