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: FastMCP Dummy Server

特征

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

工具

  • 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

Resources

Looking for Admin?

Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.

Latest Blog Posts

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