Token导航 LogoToken导航TokenDH.com
MCP Server Kb logo
AI代理未说明官方级别未说明来源级核验

MCP Server Kb

MCP Server

通过MCP协议将OpenAI与自定义工具集成,实现AI动态调用知识库等功能的后端系统对接。

工具数

1

提示词数

0

GitHub Stars

0

资源数

0
协议转换PythonAI代理

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

AashishPalSingh

提供方

AashishPalSingh

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

OpenAI与MCP的集成

本节演示如何将模型上下文协议(MCP)与OpenAI的API集成,以创建一个系统,使OpenAI可以访问和使用MCP服务器提供的工具。

概述

此示例显示了如何:

  1. 创建一个公开知识库工具的MCP服务器
  2. 将OpenAI连接到此MCP服务器
  3. 允许OpenAI在响应用户查询时动态使用这些工具

连接方法

此示例使用 运输 用于客户端和服务器之间的通信,这意味着:

  • 客户端和服务器在不同的进程中运行

数据流说明

  1. 用户查询:用户向系统发送查询(例如,“我们公司的假期政策是什么?”)
  2. OpenAI API:OpenAI从MCP服务器接收查询和可用工具
  3. 工具选择:OpenAI根据查询决定使用哪些工具
  4. MCP客户端:客户端接收OpenAI的工具调用请求并将其转发给MCP服务器
  5. MCP服务器:服务器执行所请求的工具(例如,检索知识库数据)
  6. 响应流:工具结果通过MCP客户端流回OpenAI
  7. 最终响应:OpenAI生成包含工具数据的最终响应

OpenAI如何执行工具

OpenAI的函数调用机制通过以下步骤与MCP工具配合使用:

  1. 工具注册:MCP客户端将MCP工具转换为OpenAI的函数格式
  2. 工具选择:OpenAI根据用户查询决定使用哪些工具
  3. 工具执行:MCP客户端执行所选工具并返回结果
  4. 上下文集成:OpenAI将工具结果纳入其响应中

MCP的作用

MCP是AI模型和后端系统之间的标准化桥梁:

  • 标准化:MCP为AI模型与工具交互提供了一致的接口
  • 抽象:MCP抽象了后端系统的复杂性
  • 安全:MCP允许您精确控制哪些工具和数据暴露给AI模型
  • 灵活性:您可以在不更改AI集成的情况下更改后端实现

实现细节

服务器(server.py)

MCP服务器公开了一个 get_knowledge_base 从JSON文件中检索问答对的工具。

客户(client.py)

客户:

  1. 连接到MCP服务器
  2. 将MCP工具转换为OpenAI的函数格式
  3. 处理OpenAI和MCP服务器之间的通信
  4. 处理工具结果并生成最终响应

知识库(data/kb.json)

包含可通过MCP服务器查询的有关公司政策的问答对。

运行示例

服务器

docker build -t ashujss11/mcp-server .

docker run -p 8050:8050 -d --name mcp-server ashujss11/mcp-server

  1. 确保已安装所需的依赖项
  2. 在中设置OpenAI API密钥 .env 文件
  3. 运行客户端: python client.py

注意:使用本例中使用的stdio传输,您不需要单独运行服务器,因为客户端会自动启动它。

响应

Initialized SSE client...
Listing tools...

Connected to server with tools: ['get_knowledge_base']

Query: What is our company's vacation policy?

-------START AI Message-------
[
  {
    'role': 'user',
    'content': "What is our company's vacation policy?"
  },
  ChatCompletionMessage(content=None,
  refusal=None,
  role='assistant',
  annotations=[
    
  ],
  audio=None,
  function_call=None,
  tool_calls=[
    ChatCompletionMessageToolCall(id='call_OrCTQBx5Xhsubq2eXge662aU',
    function=Function(arguments='{}',
    name='get_knowledge_base'),
    type='function')
  ]),
  {
    'role': 'tool',
    'tool_call_id': 'call_OrCTQBx5Xhsubq2eXge662aU',
    'content': "Here is the retrieved knowledge base:\n\nQ1: What is our company's vacation policy?\nA1: Full-time employees are entitled to 20 paid vacation days per year. Vacation days can be taken after completing 6 months of employment. Unused vacation days can be carried over to the next year up to a maximum of 5 days. Vacation requests should be submitted at least 2 weeks in advance through the HR portal.\n\nQ2: How do I request a new software license?\nA2: To request a new software license, please submit a ticket through the IT Service Desk portal. Include the software name, version, and business justification. Standard software licenses are typically approved within 2 business days. For specialized software, approval may take up to 5 business days and may require department head approval.\n\nQ3: What is our remote work policy?\nA3: Our company follows a hybrid work model. Employees can work remotely up to 3 days per week. Remote work days must be coordinated with your team and approved by your direct manager. All remote work requires a stable internet connection and a dedicated workspace. Core collaboration hours are 10:00 AM to 3:00 PM EST.\n\nQ4: How do I submit an expense report?\nA4: Expense reports should be submitted through the company's expense management system. Include all receipts, categorize expenses appropriately, and add a brief description for each entry. Reports must be submitted within 30 days of the expense. For expenses over $100, additional documentation may be required. All reports require manager approval.\n\nQ5: What is our process for reporting a security incident?\nA5: If you discover a security incident, immediately contact the Security Team at security@company.com or call the 24/7 security hotline. Do not attempt to investigate or resolve the incident yourself. Document what you observed, including timestamps and affected systems. The Security Team will guide you through the incident response process and may need your assistance for investigation.\n\n"
  }
]
-------END AI Message-------

Response: Our company's vacation policy is as follows:

- Full-time employees are entitled to 20 paid vacation days per year.
- Vacation days can be taken after completing 6 months of employment.
- Unused vacation days can be carried over to the next year, with a maximum carryover of 5 days.
- Vacation requests should be submitted at least 2 weeks in advance through the HR portal.

目录标签

目录标签

协议转换PythonAI代理AI集成本地部署知识库查询后端对接工具调用

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP