mcpField
M
mcp-server-demo

mcp-server-demo

远程服务
github.com/dev-johnny-gh开发工具085 周前更新
代码仓库

关于 mcp-server-demo

mcp-server-demo 展示了通过 LibreChat、Ollama 和本地 MongoDB 搭建及使用 MCP 工具的流程。示例工具可查询本机和外部 IPv4、IPv6 地址。

主要功能

  1. 01提供本机与外部 IP 查询工具
  2. 02包含 LibreChat 配置示例
  3. 03使用 Ollama 模型创建 Agent

适用场景

  1. 01在 LibreChat 中测试 IP 查询工具
  2. 02通过 Agent 获取本机或外部 IP 地址

MCP 相关

该示例将 SSE MCP 服务配置到 LibreChat,让 Agent 调用本机及外部 IP 查询工具。

配置

远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。

服务地址http://localhost:3000/sse
一键复制安装命令
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。

工具

详细介绍

安装

  1. cd IpServer && npm install && npm run build && npm run start

  2. 安装本地 mongodb 服务,并在 mongodb://127.0.0.1:27017 上提供服务

  3. cd LibreChat && git clone [email protected]:danny-avila/LibreChat.git && mv .env.example .env && npm install && npm run frontend && npm run backend

  4. 将以下配置添加到 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"
  1. 下载并运行 ollama,从 https://ollama.ai/models/ 下载一个模型,并在 http://localhost:11434/ 上运行 ollama

使用方法

  1. 访问 http://localhost:3080/,查看 LibreChat 界面。

  2. 创建一个名为 "Ollama" 的新 Agent,选择 ollama 作为模型提供方,并选择一个模型

  3. 点击下方的 Add Tools 按钮,添加 get-external-ip、get-local-ip-v6、get-external-ip-v6、get-local-ip 工具

  4. 向 Agent 提问:我的本地 IP 地址是什么?/ 我的外部 IP 地址是什么?/ 我的外部 IPv6 地址是什么?/ 我的内部 IPv6 地址是什么?

  5. Agent 应调用你的工具并返回结果。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。