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

mcpbase server

MCP Server

一个生产就绪的模型上下文协议(MCP)服务器实现,提供工具、资源和多种传输模式,用于构建MCP兼容的AI助手和自动化工具。

工具数

3

提示词数

0

GitHub Stars

0

资源数

0
API集成自动化Python本地部署STDIO

安装说明

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

作者 / 组织

ravikant1918

提供方

ravikant1918

最后核验

2026/5/17 20:20

快速接入

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

命令预览

pip install -r requirements.txt

详细介绍

MCPBase-一个最小但结构化的MCP服务器

![License: MIT](https://opensource.org/licenses/MIT) ![Python 3.9+](https://www.python.org/downloads/) ![Model Context Protocol](https://modelcontextprotocol.io/)

生产准备就绪 模型上下文协议(MCP) 服务器实现具有干净的架构、全面的工具和多种传输模式。MCPBase为构建与MCP兼容的AI助手和自动化工具提供了坚实的基础。

✨ 特性

🛠️ 工具

  • 回声工具:带有时间戳和元数据的消息回声
  • 反转工具:文本反转与输入验证
  • 计算器工具:基本算术运算(加、减、乘、除)

📦 资源

  • 键值存储:具有get/set/list/delete操作的内存存储
  • REST API:HTTP端点,便于测试和集成

🎯 提示

  • 代码审查:具有特定语言指南的高级代码审查模板
  • 可定制的:支持不同的编程语言和重点领域

🚀 运输方式

  • 标准:stdin/stdout上的标准MCP协议
  • 超文本传输协议:用于测试和调试的REST API端点
  • 上海证券交易所:服务器发送事件以进行实时通信

🏗️ 建筑

  • 模块化设计:明确区分关注点
  • 生产就绪:全面的错误处理和记录
  • 类型安全:整个代码库中的完整类型提示
  • 后端不可知:支持FastMCP和标准MCP后端

📋 需求

  • Python 3.9+
  • MCP包: pip install mcp
  • 可选的:FastAPI和Uvicorn用于HTTP端点

🚀 快速开始

安装

# Clone the repository
git clone https://github.com/mcpbase/mcpbase.git
cd mcpbase

# Install dependencies
pip install -r requirements.txt

# Run self-tests
python server.py --self-test

# Start the server
python server.py

基本用法

# Start MCP server (stdio mode) - default
python server.py

# Start HTTP server for testing
python server.py --http

# Start SSE server
python server.py --sse

# Run comprehensive self-tests
python server.py --self-test

# Show help
python server.py --help

📖 使用示例

MCP协议(stdio)

# Start the MCP server
python server.py

# Example JSON-RPC 2.0 initialize message
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' | python server.py

HTTP API

# Start HTTP server
python server.py --http

# Health check
curl http://localhost:8000/health

# List available tools
curl -X POST http://localhost:8000/tools/list

# Invoke echo tool
curl -X POST http://localhost:8000/tools/invoke \\
     -H "Content-Type: application/json" \\
     -d '{
       "name": "tools.echo", 
       "arguments": {"message": "Hello MCPBase!"}
     }'

# Use calculator
curl -X POST http://localhost:8000/tools/invoke \\
     -H "Content-Type: application/json" \\
     -d '{
       "name": "tools.calculator", 
       "arguments": {"operation": "add", "a": 15, "b": 25}
     }'

# Get resource
curl -X POST http://localhost:8000/resources/get \\
     -H "Content-Type: application/json" \\
     -d '{"uri": "kv://example_key"}'

# Set resource value
curl -X POST http://localhost:8000/resources/set \\
     -H "Content-Type: application/json" \\
     -d '{"key": "my_key", "value": "my_value"}'

服务器发送事件(SSE)

# Start SSE server
python server.py --sse

# Connect to SSE endpoint
curl http://localhost:8000/sse

🏗️ 项目结构

mcpbase/
├── README.md                 # This file
├── requirements.txt          # Python dependencies
├── server.py                # Main entry point
│
├── mcpbase/                 # Main package
│   ├── __init__.py          # Package initialization
│   ├── server.py            # Core server implementation
│   │
│   ├── config/              # Configuration management
│   │   └── __init__.py      # Server settings and registries
│   │
│   ├── tools/               # Tool implementations
│   │   ├── __init__.py      # Tool exports
│   │   ├── basic_tools.py   # Echo and reverse tools
│   │   └── math_tools.py    # Calculator tool
│   │
│   ├── prompts/             # Prompt templates
│   │   ├── __init__.py      # Prompt exports
│   │   └── development_prompts.py  # Code review prompts
│   │
│   └── utils/               # Utility modules
│       ├── __init__.py      # Utility exports
│       ├── logging_setup.py # Logging configuration
│       ├── mcp_backends.py  # MCP backend detection
│       ├── resources.py     # Resource implementations
│       └── validation.py    # Data validation classes

⚙️ 配置

MCPBase使用环境变量进行配置。复制 .env.example.env 并根据需要修改值:

cp .env.example .env

环境变量

# Server settings
MCPBASE_SERVER_NAME="MCPBase Server"
MCPBASE_SERVER_VERSION="1.0.0"

# Network settings
MCPBASE_DEFAULT_HOST="0.0.0.0"
MCPBASE_DEFAULT_HTTP_PORT=8000

# Development settings
MCPBASE_DEBUG=false
MCPBASE_RELOAD=false

# Logging
MCPBASE_LOG_LEVEL="INFO"

🔧 发展

添加新工具

  1. 在中创建新的工具功能 mcpbase/tools/:
# mcpbase/tools/my_tools.py
async def my_custom_tool(input_param: str) -> Dict[str, Any]:
    """My custom tool implementation."""
    return ToolResult.success(f"Processed: {input_param}").to_dict()
  1. 在中注册该工具 mcpbase/config/__init__.py:
TOOL_REGISTRY = {
    # existing tools...
    "my_tool": {
        "name": "tools.my_tool",
        "description": "My custom tool",
        "module": "mcpbase.tools.my_tools", 
        "function": "my_custom_tool"
    }
}
  1. 更新中的服务器注册 mcpbase/server.py

添加新资源

资源通过 KeyValueStore 类在 mcpbase/utils/resources.py。您可以扩展此模式或按照相同的模式创建新的资源类。

添加新提示

  1. 在中创建提示函数 mcpbase/prompts/:
# mcpbase/prompts/my_prompts.py
async def my_prompt_template(param: str = "default") -> str:
    """Generate my custom prompt."""
    return f"Custom prompt with {param}"
  1. 注册 mcpbase/config/__init__.py 并更新服务器注册。

🧪 测试

MCPBase包括全面的自检:

# Run all tests
python server.py --self-test

# Expected output:
# ✓ Server initialization successful
# ✓ KV store operations working  
# ✓ Tool imports successful
# ✓ Echo tool working
# ✓ Reverse tool working
# ✓ Calculator tool working
# ✓ Code review prompt working
# ✓ Configuration valid
# 🎉 All self-tests passed successfully!

手动测试

测试单个组件:

# Test tools directly
import asyncio
from mcpbase.tools import echo_tool, calculator_tool

async def test():
    result = await echo_tool("Hello World")
    print(result)
    
    calc_result = await calculator_tool("multiply", 6, 7)
    print(calc_result)

asyncio.run(test())

🔌 API 参考

工具

回声工具

  • 名字: tools.echo
  • 参数: message: str
  • 退货:带有时间戳的回声消息

反转工具

  • 名字: tools.reverse
  • 参数: text: str
  • 退货:带有元数据的反转文本

计算器工具

  • 名字: tools.calculator
  • 参数: operation: str, a: float, b: float
  • 运营: add, subtract, multiply, divide
  • 退货:计算结果

资源

键值存储

  • 统一资源标识符: kv://
  • 运营:获取、设置、列出、删除
  • 格式:JSON

提示

代码审查

  • 名字: code_review
  • 参数: code: str, language: str, focus: str
  • 退货:格式化代码审查模板

🚀 生产部署

Docker部署

FROM python:3.9-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
EXPOSE 8000

CMD ["python", "server.py", "--http"]

环境变量

# Production settings
MCPBASE_DEBUG=false
MCPBASE_RELOAD=false
MCPBASE_ENABLE_FASTAPI=true

系统化服务

[Unit]
Description=MCPBase Server
After=network.target

[Service]
Type=simple
User=mcpbase
WorkingDirectory=/opt/mcpbase
ExecStart=/usr/bin/python3 server.py
Restart=on-failure

[Install]
WantedBy=multi-user.target

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支: git checkout -b feature/amazing-feature
  3. 提交您的更改: git commit -m 'Add amazing feature'
  4. 推到分支: git push origin feature/amazing-feature
  5. 打开拉取请求

开发环境设置

# Development installation
git clone https://github.com/mcpbase/mcpbase.git
cd mcpbase
pip install -r requirements.txt

# Enable development mode
export MCPBASE_DEBUG=true
export MCPBASE_RELOAD=true

# Run tests
python server.py --self-test

📝 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

🙏 致谢

📚 资源

🆘 支持

  • 问题:
  • 讨论:
  • 文档: 维基

______________________________________________________________________

MCPBase -构建人工智能助手集成的未来,一次一个协议。 🚀

目录标签

目录标签

API集成自动化Python本地部署STDIOAI助手协议服务器自动化工具模型上下文协议RESTAPI

接入字段

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

stdio

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

none

工具数量(toolCount,工具数)

3

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdionone部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP