模型上下文协议服务器

一个基于FastMCP的模型上下文协议服务器,提供数学运算、个性化问候消息生成和文本摘要功能。

  • by Anuragck
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Anuragck/mcp-server-demo

使用说明

MCP Server Demo

A Model Context Protocol (MCP) server demonstrating tools, resources, and prompts using FastMCP.

Features

  • Tools: Mathematical operations (addition)
  • Resources: Personalized greeting messages
  • Prompts: Greeting generation and text summarization

Prerequisites

  • macOS
  • Python 3.8+

Installation

1. Install uv (Python package manager)

curl -LsSf https://astral.sh/uv/install.sh | sh

2. Initialize Project

uv init mcp-server-demo
cd mcp-server-demo

3. Create Virtual Environment

uv venv
source .venv/bin/activate

4. Install Dependencies

uv add "mcp[cli]"

5. Install MCP Inspector (Optional)

npx @modelcontextprotocol/inspector

Usage

Run the MCP Server

uv run mcp dev main.py

Available Tools

  • add(a: int, b: int) -> int: Add two numbers

Available Resources

  • greeting/{name}: Get a personalized greeting message

Available Prompts

  • greet_user(name: str, style: str = "friendly"): Generate greeting prompts
    • Styles: "friendly", "formal", "casual"
  • summarize_text(text: str): Summarize text in one sentence

Development

The server is built using FastMCP and includes:

  • Tools: Functions that can be called by MCP clients
  • Resources: Named data sources that can be accessed
  • Prompts: Template prompts for common tasks

License

MIT