MCP 伺服器展示

by etrex

2 stars
102 downloads
Not rated
GitHub

About

MCP 伺服器展示是一個練習用的 Model Context Protocol (MCP) 伺服器實作,旨在幫助開發者學習和了解 MCP 協議的運作原理。它提供兩種不同的實作方式(基礎與結構化),並支援與 Claude 整合。

Details

Author
etrex
GitHub stars
2
Downloads
102
Categories
Other

- 提供基礎實作(simple_server.rb)與結構化實作(demo.rb)
- 支援與 Claude 桌面應用整合
- 可使用 MCP Inspector 進行互動式測試
- 支援 STDIO 直接測試與 PIP 快速測試
- 遵循 MIT 授權條款

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCP 伺服器展示
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

環境需求為 Ruby 以及 Node.js 和 npm(用於 MCP inspector)。透過修改 Claude 的設定檔,加入指定 ruby 命令與 demo.rb 路徑的 JSON 結構來整合。測試可透過 MCP Inspector 或直接使用 STDIO 方式執行。

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp \u4f3a\u670d\u5668\u5c55\u793a": {
            "mcp-server-demo-etrex": {
                "command": "npx",
                "args": [
                    "@modelcontextprotocol/inspector",
                    "ruby",
                    "demo.rb"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-server-demo-etrex": {
        "command": "npx",
        "args": [
            "@modelcontextprotocol/inspector",
            "ruby",
            "demo.rb"
        ]
    }
}

MCP 伺服器展示

English Version

這個專案是一個練習用的 Model Context Protocol (MCP) server 實作,主要目的是為了學習和了解 MCP 的運作原理。

目的

本專案的主要目標:
- 學習 MCP 協議的基本概念
- 理解 MCP server 的運作機制
- 實作一個簡單的 MCP server 來加深理解

環境需求

環境需求:
- Ruby
- Node.js 和 npm(用於 MCP inspector)

與 Claude 整合

與 Claude 整合的步驟:

1. 複製或下載此專案到本地端。
2. 修改 Claude 的設定檔,加入以下 JSON 結構:

{
  "mcpServers": {
    "mcp_server_demo": {
      "command": "ruby",
      "args": [
        "<path_to_repository>/demo.rb"
      ]
    }
  }
}

注意:請將 <path_to_repository> 替換為您本地端專案的絕對路徑。

3. 重新啟動 Claude 以套用新設定。

測試方法

1. 使用 MCP Inspector

1. 安裝 MCP inspector:

npm install -g @modelcontextprotocol/inspector

2. 使用 inspector 運行伺服器:

npx @modelcontextprotocol/inspector ruby simple_server.rb

npx @modelcontextprotocol/inspector ruby demo.rb
npx @modelcontextprotocol/inspector ruby server_with_fast_mcp.rb

2. STDIO 測試

MCP Server 使用標準輸入輸出(STDIO)進行通訊。有兩種測試方式:

方式一:直接執行並手動輸入(推薦)

1. 首先啟動伺服器:

ruby simple_server.rb

2. 然後在終端機中輸入 JSON-RPC 指令(每行一個指令):

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{"sampling":{},"roots":{"listChanged":true}},"clientInfo":{"name":"mcp-inspector","version":"0.0.1"}}}
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"_meta":{"progressToken":0},"name":"calculate_sum","arguments":{"a":1,"b":2,"env":""}}}

這種方式可以保持伺服器持續運行,進行多次測試。使用 Ctrl+C 可以結束伺服器。

方式二:使用 PIPE(單次測試)

使用 PIPE(|)可以快速測試單個指令,但每次指令結束後伺服器就會關閉:

echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | ruby simple_server.rb

注意:使用 PIPE 時,每次指令執行完成後,STDIN 會收到 EOF 並自動關閉伺服器。如果需要連續測試多個指令,建議使用方式一。

開發說明

本專案提供兩種不同的實作方式,幫助理解 MCP 協議:

基礎實作 - Simple Server

- simple_server.rb:單一檔案的基礎實作 - 完整展示 MCP 協議的基本概念 - 包含完整的 JSON-RPC 請求/回應流程 - 展示工具註冊和呼叫機制 - 適合學習 MCP 的基本運作原理

架構化實作 - Demo Server

- demo.rb:主要進入點 - 展示如何組織一個完整的 MCP 伺服器專案 - 使用模組化的方式管理工具和處理程序 - mcp_server.rb:核心 MCP 協議處理 - 抽象化協議層的實作 - 提供可重用的基礎類別和方法 - 展示如何建構可擴展的 MCP 伺服器架構

授權條款

MIT 授權

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.