Skip to main content
Glama
ugundhar

MCP Server Basic Example

by ugundhar

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

Related MCP server: MCP Server Basic Example

特征

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

工具

  • 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 的你好

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A simple implementation of a Model Context Protocol server that demonstrates core functionality including mathematical tools (add, subtract) and personalized greeting resources.
    98
    GPL 3.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    A basic implementation of a Model Context Protocol server that demonstrates core functionality with simple math tools (add, subtract) and greeting resources for AI assistants like Claude.
    GPL 3.0
  • F
    license
    Not graded
    quality
    D
    maintenance
    A demonstration implementation of a Model Context Protocol server that provides simple mathematical tools (add, subtract) and personalized greeting resources.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that provides basic tools for arithmetic operations (addition) and dynamic greeting resources, demonstrating MCP integration patterns for other projects and clients.
    10 npm
    ISC