Cover image

该项目展示了如何将MCP协议与Azure OpenAI一起使用。它提供了一个简单的示例,可以通过MCP服务器和客户端无缝与OpenAI的API进行交互。

3 years

Works with Finder

3

Github Watches

3

Github Forks

3

Github Stars

OpenAI MCP Getting Started Example

This project showcases how to use the MCP protocol with OpenAI. It provides a simple example to interact with OpenAI's API seamlessly via an MCP server, host and clients.

MCP server supported features and capabilities

This sample provides an MCP server implementation that supports the following features:

Feature Completed
SSE
HTTP Streaming
AuthN/Z
Tools
Resources
Prompts
Sampling

Getting Started

To get started with this project, follow the steps below:

Prerequisites

  • Node.js and npm (version 22 or higher)
  • An OpenAI compatible endpoint:
    • An OpenAI API key
    • Or, a GitHub token, if you want to use the GitHub models: https://gh.io/models
    • Or, if you are using Azure OpenAI, you need to have an Azure OpenAI resource and the corresponding endpoint.

Installation

  1. Clone the repository:

    git clone https://github.com/manekinekko/openai-mcp-example.git
    cd openai-mcp-example
    
  2. Install the dependencies:

    npm install
    

Configuration

This sample supports the follwowing providers:

  • Azure OpenAI,
  • OpenAI,
  • GitHub Models.

Azure OpenAI

In order to use Keyless authentication, using Azure Managed Identity, you need to provide the AZURE_OPENAI_ENDPOINT environment variable in the .env file:

AZURE_OPENAI_ENDPOINT="https://<ai-foundry-openai-project>.openai.azure.com"
MODEL="gpt-4.1"

# Optional: If you want to use the API key authentication.
#AZURE_OPENAI_API_KEY=your_azure_openai_api_key

And make sure to using the Azure CLI to log in to your Azure account and follow the instructions to selection your subscription:

az login

OpenAI

To use the OpenAI API, you need to set your OPENAI_API_KEY key in the .env file:

OPENAI_API_KEY=your_openai_api_key
MODEL="gpt-4.1"

GitHub Models

To use the GitHub models, you need to set your GITHUB_TOKEN and GITHUB_MODEL in the .env file:

GITHUB_TOKEN=your_github_token
GITHUB_MODEL="openai/gpt-4.1"

Usage

  1. Run the MCP server:

    npm run server
    
  2. Run the MCP host in a separate terminal:

    npm run host
    

You should see a response like the following:

Authentication method: Azure OpenAI Entra ID (keyless)

MCP Host Started!
Connected to the following servers:
* math-server: http://localhost:4321/sse
Available tools:
- calculate_sum: Calculate the sum of two numbers
- calculate_product: Calculate the product of two numbers
- calculate_difference: Calculate the difference of two numbers
- calculate_division: Calculate the division of two numbers

Query: what is 40+2?
Agent:
[Thinking] Using tool "calculate_sum" with args "{\"a\":40,\"b\":2}"
[Thinking] Tool calculate_sum result: The sum of 40 and 2 is 42.
[Thinking] The result of 40 + 2 is 42.

Agent:
The result of 40 + 2 is 42.

Query:

Debugging and inspection

You can use the DEBUG environment variable to enable verbose logging for the OpenAI SDK:

DEBUG=true npm run host

In order to inspect the MCP servers, run the following command in a separate terminal, and follow the instructions:

npm run inspect

License

This project is licensed under the MIT License. See the LICENSE file for details.

相关推荐

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • sigoden
  • 使用普通的bash/javascript/python函数轻松创建LLM工具和代理。

  • hkr04
  • 轻巧的C ++ MCP(模型上下文协议)SDK

  • rulego
  • ⛓️Rulego是一种轻巧,高性能,嵌入式,下一代组件编排规则引擎框架。

  • RockChinQ
  • 😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack

  • dmayboroda
  • 带有可配置容器的本地对话抹布

  • paulwing
  • 使用MCP服务创建的测试存储库

    Reviews

    2.6 (8)
    Avatar
    user_yVOHrj1N
    2025-04-24

    Azure-openai-mcp-example by manekinekko is a fantastic solution for integrating OpenAI capabilities into your applications seamlessly. The documentation is clear and concise, making it easy to get started. The sample code provided is extremely helpful for understanding how to implement and customize the functionalities. Highly recommended for developers looking to leverage AI in their projects!

    Avatar
    user_0TzYPtV2
    2025-04-24

    I've been using azure-openai-mcp-example by manekinekko and it has significantly improved my workflow. The documentation is clear, making it easy to set up and start. This tool leverages the power of Azure and OpenAI seamlessly, helping me enhance productivity and efficiency in my projects. Highly recommended for anyone looking to integrate AI into their applications effortlessly.

    Avatar
    user_4L9RXhz1
    2025-04-24

    As a dedicated user of azure-openai-mcp-example, I must say it's an exceptional product by manekinekko. The seamless integration and user-friendly interface make it incredibly effective for my projects. It's a game-changer, especially in handling and processing openai APIs effortlessly. Highly recommended!

    Avatar
    user_KcudFbxD
    2025-04-24

    As a dedicated user of the azure-openai-mcp-example, I must say it's a game-changer! The integration is seamless, and the performance meets all my needs effortlessly. Kudos to manekinekko for crafting such a user-friendly and efficient solution. Highly recommend it for anyone looking to optimize their MCP applications!

    Avatar
    user_KpGe7h84
    2025-04-24

    I've been using azure-openai-mcp-example by manekinekko, and it has been a game changer for my projects. This well-documented and easy-to-use application integrates Azure and OpenAI seamlessly, providing incredible functionality and performance. Highly recommend for anyone looking to enhance their development workflow!

    Avatar
    user_Fy6APfnr
    2025-04-24

    As a dedicated user of the Azure OpenAI MCP example by manekinekko, I find this tool incredibly useful for integrating advanced AI capabilities into my applications. The seamless setup and comprehensive documentation make it accessible for developers of all skill levels. The robust functionality and reliability have significantly enhanced my project's performance. Highly recommend!

    Avatar
    user_dW3f5q02
    2025-04-24

    I have been using the azure-openai-mcp-example by manekinekko for a while now, and I am thoroughly impressed. The seamless integration and user-friendly interface make it an invaluable tool for developers. The comprehensive documentation and welcoming messages provide a smooth onboarding experience. Highly recommend it to anyone in need of a reliable and efficient solution.

    Avatar
    user_y2956Aqs
    2025-04-24

    The azure-openai-mcp-example by manekinekko is an impressive and user-friendly application. It seamlessly integrates with Azure and OpenAI, providing robust functionalities that are both practical and efficient. Highly recommended for anyone looking to simplify their AI and cloud interactions.