使用 MCP 查询 Routing Director
使用本主题可使用模型上下文协议 (MCP) 查询 Routing Director。
MCP 概述和实施
Juniper Routing Director 利用模型上下文协议 (MCP),使 Microsoft Copilot、ChatGPT 和 Claude 等 AI 代理能够建立安全连接。通过这种集成:
-
网络运维人员可以使用 AI 代理查询 Routing Director。
-
AI 代理可以将 Routing Director 作为数据源进行访问,并为网络运营商提供准确、上下文感知的查询响应。
MCP 包作为开源代码存储在 GitHub 存储库中, https://github.com/Juniper/routing-director-mcp-server ,并通过 MCP 注册表分发。
优势
MCP 服务器可帮助网络运营商以对话方式查询网络数据、创建仪表板和访问 KPI,而无需编写代码或学习复杂的 API 语法。
部署 MCP 服务器
以下是在主机(例如笔记本电脑)上部署 MCP 服务器的先决条件:
-
Python 版本 3.10 或 3.11。
-
使用有效的 UI 身份验证凭据(用户名和密码或 API 令牌)访问 Routing Director
-
Routing Director API 的可访问性
-
创建 Python 虚拟环境以安装运行 MCP 服务器所需的软件包。
以下是部署 MCP 服务器的步骤:
-
从 GitHub MCP 存储库和官方 MCP 注册表下载 MCP 包。
源代码维护在 https://github.com/Juniper/routing-director-mcp-server 下的 GitHub 存储库中。
-
在 Python 虚拟环境中,使用
pip3 install -r requirements.txt安装 MCP 包中的 requirement.txt 文件中定义的所有要求。 -
创建 MCP 服务器配置文件 (config.json)。
配置文件指定如何访问 Routing Director、如何进行身份验证,以及要公开哪些组件 API,作为查询 Routing Director 的工具。以下是配置文件的示例:
以下是示例 MCP 服务器配置文件:
{ "http_url": "https://your-routing-director.example.com", "org_id": "your-organization-uuid", "auth": { "type": "basic", "username": "your-username@company.com", "password": "your-password" }, "components": ["ems", "device-kpi", ...] }其中,
-
http_url是 Routing Director 的基本 URL。 -
org_id是要查询的 Routing Director 中组织的唯一标识符。 -
auth定义身份验证。在下auth定义以下内容:-
type- 用于连接到 Routing Director 的身份验证方法。它可以采用值或basictoken如果输入
basic,请输入以下值:-
username- 用于访问 Routing Director 的用户名。 -
password- 用户名密码。
如果输入
token,请输入 Routing Director 生成的 API 令牌。例如:auth": { "type": "token", "token": "YOUR-TOKEN-HERE" },有关在 Routing Director 中生成 API 令牌的信息,请参阅 管理 API 令牌。
-
-
-
components是可查询的 Routing Director 组件列表。Components可以采用以下值之一:-
ems— 使用该ems组件搜索、确认或取消确认 Routing Director 上报告的告警。 -
juniper-resiliency-interface- 使用该juniper-resiliency-interface组件获取由瞻博网络弹性配置接口 (JRI) 生成并由 Routing Director 收集的转发、路由和操作系统异常事件。 -
device-kpi— 使用 device-kpi 组件检索 Routing Director 收集的设备系统日志消息。
components是可选参数。如果未定义,则components考虑所有组件。 -
-
-
(选答)在 MCP 服务器和 MCP 客户端之间启用身份验证。
您可以将基于文件的令牌身份验证用于 MCP 客户端与 MCP 服务器之间的通信。要生成令牌,请在本地系统中执行以下命令:
python utils/mcp/token_cli.py generate --client-id sv@juniper.net --description "Token for SV"
其中, client-id 是用于生成身份验证令牌的 ID。
以下是生成的输出示例: 将生成的令牌保存在 .tokens 文件中。默认情况下,令牌保存在 GitHub MCP 存储库的根目录中。Generated new token: ID: my-client Token: apa_CA98sH_VwEBd79aHA6O9NxbhXQN_RqaK Description: Production API
-
启动 MCP 服务器。
python RoutingDirectorMCP.py -c /path/to/your/config.json
-
配置 AI 代理以与 MCP 服务器通信。请参阅 配置 AI 代理以与 MCP 服务器通信。
AI 代理可以使用
stdio和streamable-http作为传输模式与 MCP 服务器通信。
现在可以使用 Microsoft Copilot 或 ChatGPT 等 AI 代理从 Routing Director 查询数据。
配置 AI 代理以与 MCP 服务器通信
配置 MCP 服务器后,您必须配置一个 AI 代理才能与 MCP 服务器进行通信。您可以在 AI 代理的设置中配置 MCP 服务器连接。本节提供通过 Claude 和 Copilot 配置与 MCP 服务器的连接的步骤。
配置 Claude
要配置 Claude:
-
在文本编辑器中打开 Claude 配置文件。
-
在 macOS 计算机上,在终端中运行以下命令:
~/Library/Application Support/Claude/claude_desktop_config.json -
在 Windows 计算机上,打开命令提示符并输入:
%APPDATA%\Claude\claude_desktop_config.json
-
-
添加您的 MCP 服务器配置,如下所示:
{ "mcpServers": { "RoutingDirector": { "command": "/Users/username/path-to-virtual-environment/.mcp_venv/bin/python", "args": [ "/Users/username/path-to-mcp-python-script/RoutingDirectorMCP.py", "-c", "/Users/username/path-to-config-json/config.json", "-t", "stdio" ] } } } -
保存文件。
-
重新启动 Claude。
-
验证 Claude 与 MCP 服务器的连接。
如果 MCP 服务器工具(API 调用)列在 + > 连接器下,则 Claude 连接到 MCP 服务器。
或者,您可以查看 VS code 扩展中列出的 MCP 服务器工具(API 调用)。
要确保 MCP 服务器已正确启动,请查看 MCP 服务器日志。日志是根据与 AI 代理的通信类型生成的:
-
Starting MCP server 'Juniper Routing Directory' with transport 'stdio'如果使用。stdio -
INFO Starting MCP server 'Juniper Routing Directory' with transport 'http' on http://127.0.0.1:30030/mcp如果使用。streamable-http
-
配置 Copilot
若要配置 Copilot,请执行以下操作:
-
打开 Virtual Studio (VS) 代码。
或者,您可以使用支持 Copilot 和 MCP 服务器的任何其他集成开发环境 (IDE),
-
使用以下方法之一打开 MCP 设置文件:
-
在 macOS 上,在终端中运行以下命令:
Open ~/Library/Application\ Support/Code/User/mcp.json
其中, user 是您在 macOS 计算机上的用户名。
-
在 Windows 计算机上,打开命令提示符并输入:
C:/Users/YourUserName/AppData/Roaming/Code/User/mcp.json
Where 是 user 您在 Windows 计算机上的用户名。
-
-
将 MCP 服务器配置添加到设置文件中,如下所示:
{ "mcpServers": { "RoutingDirector": { "command": "/Users/username/path-to-virtual-environment/.mcp_venv/bin/python", "args": [ "/Users/username/path-to-mcp-python-script/RoutingDirectorMCP.py", "-c", "/Users/username/path-to-config-json/config.json", "-t", "stdio" ] } } }其中,
-
保存文件。
-
关闭并重新打开 VS 代码,使 MCP 配置更改生效。
-
验证 Copilot 是否已与 MCP 服务器连接。
如果您在 VS code 的“输出”面板中发现指示成功连接到 MCP 服务器的消息,则 Copilot 将连接到 MCP 服务器。
或者,您可以查看 VS code 扩展中列出的 MCP 服务器工具(API 调用)。
要确保 MCP 服务器已正确启动,请查看 MCP 服务器日志。日志是根据与 AI 代理的通信类型生成的:
-
Starting MCP server 'Juniper Routing Directory' with transport 'stdio'如果使用。stdio -
INFO Starting MCP server 'Juniper Routing Directory' with transport 'http' on http://127.0.0.1:30030/mcp如果使用。streamable-http
-