关于 mcp-server-demo
mcp-server-demo 展示了通过 LibreChat、Ollama 和本地 MongoDB 搭建及使用 MCP 工具的流程。示例工具可查询本机和外部 IPv4、IPv6 地址。
主要功能
- 01提供本机与外部 IP 查询工具
- 02包含 LibreChat 配置示例
- 03使用 Ollama 模型创建 Agent
适用场景
- 01在 LibreChat 中测试 IP 查询工具
- 02通过 Agent 获取本机或外部 IP 地址
MCP 相关
该示例将 SSE MCP 服务配置到 LibreChat,让 Agent 调用本机及外部 IP 查询工具。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
http://localhost:3000/sseclaude mcp add --transport http demo-dev-johnny-gh http://localhost:3000/sse{"mcpServers":{"demo-dev-johnny-gh":{"type":"http","url":"http://localhost:3000/sse"}}}在 Cursor 中打开{"servers":{"demo-dev-johnny-gh":{"type":"http","url":"http://localhost:3000/sse"}}}在 VS Code 中打开{"mcpServers":{"demo-dev-johnny-gh":{"type":"http","url":"http://localhost:3000/sse"}}}{"mcpServers":{"demo-dev-johnny-gh":{"serverUrl":"http://localhost:3000/sse"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
安装
-
cd IpServer && npm install && npm run build && npm run start
-
安装本地 mongodb 服务,并在 mongodb://127.0.0.1:27017 上提供服务
-
cd LibreChat && git clone [email protected]:danny-avila/LibreChat.git && mv .env.example .env && npm install && npm run frontend && npm run backend
-
将以下配置添加到 librechat.yaml 文件中:
mcpServers:
ipServer:
# type: sse # type can optionally be omitted
url: http://localhost:3000/sse
timeout: 60000 # 1 minute timeout for this server, this is the default timeout for MCP servers.
endpoints:
custom:
- name: "Ollama"
apiKey: "ollama"
# use 'host.docker.internal' instead of localhost if running LibreChat in a docker container
baseURL: "http://localhost:11434/v1/chat/completions"
models:
default:
[
"qwen2.5:3b-instruct-q4_K_M",
"mistral:7b-instruct-q4_K_M",
"gemma:7b-instruct-q4_K_M",
]
# fetching list of models is supported but the `name` field must start
# with `ollama` (case-insensitive), as it does in this example.
fetch: true
titleConvo: true
titleModel: "current_model"
summarize: false
summaryModel: "current_model"
forcePrompt: false
modelDisplayLabel: "Ollama"
- 下载并运行 ollama,从 https://ollama.ai/models/ 下载一个模型,并在 http://localhost:11434/ 上运行 ollama
使用方法
-
访问 http://localhost:3080/,查看 LibreChat 界面。
-
创建一个名为 "Ollama" 的新 Agent,选择 ollama 作为模型提供方,并选择一个模型
-
点击下方的 Add Tools 按钮,添加 get-external-ip、get-local-ip-v6、get-external-ip-v6、get-local-ip 工具
-
向 Agent 提问:我的本地 IP 地址是什么?/ 我的外部 IP 地址是什么?/ 我的外部 IPv6 地址是什么?/ 我的内部 IPv6 地址是什么?
-
Agent 应调用你的工具并返回结果。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。