Skip to main content
Glama

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

特征

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

工具

  • 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

Related MCP Servers

  • -
    security
    A
    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 -
    82
    GPL 3.0
  • -
    security
    F
    license
    -
    quality
    A minimal example server implementing the Model Context Protocol, providing addition and multiplication tools for learning and experimentation with MCP clients.
    Last updated -
  • A
    security
    F
    license
    A
    quality
    A Model Context Protocol server implementation that provides basic utility tools including echo, uppercase text conversion, and mathematical calculations.
    Last updated -
    3
    361
  • -
    security
    F
    license
    -
    quality
    A simple demonstration server for the Model Context Protocol that provides tools for creating and managing greetings with support for multiple transport methods (stdio, HTTP, SSE).
    Last updated -

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ugundhar/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server