Token导航 LogoToken导航TokenDH.com
Reference MCP Server logo
AI代理stdio官方级别未说明来源级核验

Reference MCP Server

MCP Server

一个基于FastMCP的极简HTTP MCP服务器参考实现,展示如何用现代Python工具快速构建MCP服务器。

工具数

3

提示词数

0

GitHub Stars

0

资源数

0
微服务PythonClaudeHTTP服务器Claude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

jefferyharrell

提供方

jefferyharrell

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install -e .

详细介绍

参考MCP服务器

使用FastMCP的远程HTTP MCP服务器的干净、最少的参考实现。这个项目展示了使用现代Python工具构建MCP服务器是多么简单。

ˇ突破

整个MCP服务器基本上是 10行代码:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Reference Server", stateless_http=True)

@mcp.tool()
def hello_world(message: str) -> str:
    """Say hello to the world"""
    return f"Hello, {message}!"

if __name__ == "__main__":
    mcp.run(transport="streamable-http")

That's it! FastMCP handles HTTP server setup, MCP protocol implementation, routing, error handlingeverything.

=€ Quick Start

Prerequisites

  • Python 3.11+
  • uv (recommended) or pip

Installation

# Clone or create the project
git clone 
cd reference-mcp-server

# Install dependencies with uv (recommended)
uv sync

# Or with pip
pip install -e .

Running the Server

# Default: streamable-http transport on localhost:8000
uv run python -m reference_mcp.server

# Or use the installed script
uv run reference-mcp-server

# Use SSE transport instead
MCP_TRANSPORT=sse uv run reference-mcp-server

=运输方式

此参考服务器支持以下两种MCP传输类型:

流式HTTP(默认)

  • 现代化、高效的交通
  • 新实现的默认选项
  • 在流媒体中使用HTTP/1.1
  • 更好的性能和可靠性
# Explicit streamable-http
MCP_TRANSPORT=streamable-http uv run reference-mcp-server

服务器发送事件(SSE)

  • 回退传输以实现兼容性
  • 对服务器发送的事件使用HTTP
  • 更广泛的客户支持
# Use SSE transport
MCP_TRANSPORT=sse uv run reference-mcp-server

='配置

服务器使用环境变量进行配置:

变量默认值描述
MCP_TRANSPORTstreamable-http运输类型: ssestreamable-http
MCP_HOSTlocalhost服务器主机(用于文档)
MCP_PORT8000服务器端口(用于文档)

创建一个 .env 示例中的文件:

cp .env.example .env
# Edit .env with your preferences

=集成示例

克劳德桌面

添加到您的Claude Desktop配置中:

{
  "mcpServers": {
    "reference-server": {
      "command": "uv",
      "args": [
        "run", 
        "--directory", 
        "/path/to/reference-mcp-server", 
        "reference-mcp-server"
      ]
    }
  }
}

使用mcp远程适配器

真正的功能来自mcp远程适配器,它处理兼容性:

{
  "mcpServers": {
    "reference-server": {
      "command": "mcp-remote",
      "args": ["http://localhost:8000"]
    }
  }
}

码头工人

FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install uv && uv sync
EXPOSE 8000
CMD ["uv", "run", "reference-mcp-server"]

="开发

项目结构

reference-mcp-server/
�� pyproject.toml           # Modern Python packaging
�� README.md                # This file
�� .env.example             # Environment template
�� src/
   �� reference_mcp/
       �� __init__.py
       �� server.py        # Main server (the magic 10 lines!)
       �� config.py        # Configuration handling
�� examples/
    �� configuration/       # Integration examples

添加新工具

只需添加更多 @mcp.tool() 装饰功能:

@mcp.tool()
def greet_user(name: str, greeting: str = "Hello") -> str:
    """Greet a user with a custom greeting"""
    return f"{greeting}, {name}! Welcome to our MCP server!"

@mcp.tool()
def calculate_sum(numbers: list[int]) -> int:
    """Calculate the sum of a list of numbers"""
    return sum(numbers)

FastMCP自动处理:

  • 使用Pydantic进行类型验证
  • 用于工具发现的JSON模式生成
  • 错误处理和响应
  • HTTP路由和MCP协议

运行测试

# Start the server
uv run reference-mcp-server &

# Test the hello_world tool (example with curl)
curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{"tool": "hello_world", "arguments": {"message": "World"}}'

关键设计决策

为什么选择FastMCP?

  • 零样板:无需手动设置HTTP服务器
  • 完全符合MCP:自动处理协议
  • 类型安全性:内置Pydantic验证
  • 双重运输:SSE和可流式传输的http支持
  • 生产就绪:Uvicorn驱动的HTTP服务器

为什么是无状态HTTP?

  • 简洁:不需要会话管理
  • 可扩展性:易于负载平衡和缩放
  • 可靠性:没有要丢失的连接状态
  • mcp远程兼容性:与适配器完美配合

为什么两种运输方式?

  • 流式HTTP:现代、高效、首选
  • SSE: Fallback for broader compatibility
  • Future-proof: Supports both current and legacy clients

=Ú What This Demonstrates

This reference implementation proves that building MCP servers can be:

  1. Stupidly Simple: 10 lines for a complete server
  2. Well-Architected: Modern tooling, clean structure
  3. Production Ready: Real HTTP server, proper error handling
  4. Highly Compatible: Works with all MCP client implementations

=. Next Steps

Use this as a template for:

  • Custom MCP servers: Add your domain-specific tools
  • Learning MCP: Understand the protocol without complexity
  • Prototyping: Quick proof-of-concepts for new tools
  • Production services: Scale up with additional tools and logic

The revolution is that MCP servers are no longer complex infrastructure projectsthey're just Python functions with decorators.

\<× Architecture Notes

This server leverages:

  • FastMCP: Complete MCP server framework
  • Uvicorn: Production ASGI server
  • Pydantic: Automatic validation and schemas
  • mcp-remote compatibility: Works with adapter out of the box

The combination means you get enterprise-grade MCP servers with toy-project simplicity.

______________________________________________________________________

*Built with d as part of Project Alpha*

目录标签

目录标签

微服务PythonClaudeHTTP服务器MCP协议本地部署Python开发快速原型

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

3

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP