MCP Server Basic Example

by ugundhar

Integrations

  • Provides integration for VS Code users to authenticate and connect to the MCP server through GitHub login.

MCP 服务器基本示例

这是模型上下文协议 (MCP) 服务器实现的基本示例,演示了包括工具和资源在内的核心功能。

设置步骤

  1. 初始化项目(转到任何本地文件夹并启动 powershell 或 cmd):
uv init mcp-server-basic cd mcp-server-basic
  1. 创建虚拟环境并激活

uv venv .venv\Scripts\activate
  1. 安装依赖项:
uv add "mcp[cli]"

或者

uv add -r requirements.txt

特征

该服务器实现了以下功能:

工具

  • add(a: int, b: int) :将两个数字相加
  • subtract(a: int, b: int) :从第一个数字中减去第二个数字

资源

  • greeting://{name} :返回个性化问候语

运行服务器

要使用 MCP Inspector 运行服务器进行开发:

uv run mcp dev main.py

要正常运行服务器:

uv run mcp run

要在 Claude 桌面应用程序中安装服务器:

uv run mcp install main.py

MCP 在 VS 代码中连接

  • 在 vs code 中打开文件夹/mcp-server-basic
  • 打开终端并运行以下命令:
uv run main.py
  • 单击 Cntrl+Shift+I 在 VS Code 中启动聊天
  • 使用 Github 登录并设置
  • 请按照以下步骤操作(为 vs 代码用户设置添加 mcp 配置的两种方法):

#来自 mcp 的你好

-
security - not tested
F
license - not found
-
quality - not tested

模型上下文协议服务器的示例实现,使用简单的算术工具和问候资源展示核心功能。

  1. Setup Steps
    1. Create virtual environment and activate it
      1. Features
      2. Running the Server
      3. MCP connect in VS code

    Related MCP Servers

    • A
      security
      F
      license
      A
      quality
      A server that provides tools for performing basic arithmetic operations (addition, subtraction, multiplication, division) via the Model Context Protocol.
      Last updated -
      4
      JavaScript
      • Apple
    • A
      security
      A
      license
      A
      quality
      A Model Context Protocol server providing utility tools for development and testing, offering functionalities like personalized greetings, random card drawing, and datetime formatting with an extensible architecture.
      Last updated -
      19
      355
      2
      TypeScript
      MIT License
      • Apple
      • Linux
    • A
      security
      F
      license
      A
      quality
      A simple Model Context Protocol server that provides basic arithmetic operations (addition, subtraction, multiplication, division) as tools that can be called by Large Language Models.
      Last updated -
      4
      JavaScript
    • -
      security
      -
      license
      -
      quality
      A simple implementation of a Model Context Protocol server that demonstrates core functionality including mathematical tools (add, subtract) and personalized greeting resources.
      Last updated -
      3
      Python
      GPL 3.0

    View all related MCP servers

    ID: s47rrwfdkz