Token导航 LogoToken导航TokenDH.com
shieldmcp (eaddef) logo
搜索检索stdio官方级别未说明来源级核验

shieldmcp (eaddef)

MCP Server

A shield for logging, deep debug and sanitization for MCP servers at development stage

工具数

4

提示词数

0

GitHub Stars

3

资源数

0
访问控制Python日志记录

安装说明

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

作者 / 组织

shieldmcp

提供方

shieldmcp

最后核验

2026/5/18 04:05

运行时

Python

快速接入

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

命令预览

python -m venv venv

详细介绍

屏蔽MCP

](https://www.python.org/downloads/) ![License](LICENSE) ![MCP Compatible](https://modelcontextprotocol.io)

一种用于模型上下文协议(MCP)服务器的安全中间件,在不修改官方SDK的情况下增强了安全性和监控能力。此软件包提供了用于保护和监视MCP工具调用的工具,遵循MCP文档中概述的最佳实践。在MCP开发中互动时抽象自己。

目录

特性

  • 工具访问控制:基于白名单的MCP工具访问控制
  • 结果消毒:可配置的工具输出净化
  • 结构化日志记录:使用structlog进行全面的审计日志记录
  • 速率限制:用于速率限制的令牌桶算法
  • 错误处理:标准化的错误处理和格式化
  • MCP检查器兼容:与MCP检查器工具无缝协作

需求

系统要求

  • Python 3.8或更高版本
  • pip(Python包安装程序)
  • virtualenv(建议开发)

快速开始

from shieldmcp import secure_tool
from shieldmcp.sanitizers import ToolSanitizer
from shieldmcp.rate_limit import RateLimitConfig

# Define allowed tools
ALLOWED_TOOLS = {"search", "read_file", "write_file"}

# Create a text sanitizer
text_sanitizer = ToolSanitizer.createTextSanitizer(
    max_length=1000,
    sensitive_patterns=[
        r"\b\d{16}\b",  # Credit card numbers
        r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"  # Email addresses
    ]
)

# Configure rate limiting
rate_limit = RateLimitConfig(
    requests_per_minute=60,  # 1 request per second
    burst_size=10  # Allow bursts of up to 10 requests
)

# Apply the decorator to your MCP tools
@secure_tool(
    allowed_tools=ALLOWED_TOOLS,
    sanitize_fn=text_sanitizer,
    user_id="user123",
    session_id="session456",
    rate_limit=rate_limit
)
def search(query: str):
    # Your tool implementation
    return results

组件

装饰师(decorators.py)

主要 @secure_tool 协调所有安全功能的装饰器:

@secure_tool(
    allowed_tools={"tool1", "tool2"},  # Set of allowed tool names
    sanitize_fn=your_sanitizer,        # Optional result sanitization function
    user_id="user123",                 # Optional user identifier
    session_id="session456",           # Optional session identifier
    rate_limit=RateLimitConfig(        # Optional rate limit configuration
        requests_per_minute=60,
        burst_size=10
    )
)
def your_tool():
    pass

审核日志记录(audit.py)

使用structlog进行结构化日志记录:

from shieldmcp import ToolAudit

audit = ToolAudit()
audit.logToolCallStart(
    tool_name="search",
    args={"query": "test"},
    user_id="user123"
)

访问控制(access.py)

工具访问验证:

from shieldmcp import ToolAccess

access = ToolAccess(allowed_tools={"tool1", "tool2"})
access.validateToolAccess("tool1")  # Raises ValueError if not allowed

消毒剂(sanitizers.py)

结果消毒实用程序:

from shieldmcp import ToolSanitizer

# Create a custom sanitizer
sanitizer = ToolSanitizer.createTextSanitizer(
    max_length=1000,
    sensitive_patterns=[r"\b\d{16}\b"]
)

# Use it directly
clean_text = sanitizer("Your text with sensitive data")

速率限制(rate_limit.py)

令牌桶速率限制:

from shieldmcp import RateLimitConfig

# Configure rate limits
config = RateLimitConfig(
    requests_per_minute=60,
    burst_size=10
)

最佳实践

工具访问控制

  • 始终定义允许使用的工具的白名单
  • 使用尽可能严格的工具集
  • 定期审查和更新白名单

结果消毒

  • 对所有文本输出进行消毒
  • 定义敏感数据的模式
  • 设定合理的长度限制

日志记录

  • 包括用户和会话ID(如果可用)
  • 记录成功和失败的操作
  • 使用结构化日志进行更好的分析

速率限制

  • 根据工具复杂性设置适当的限制
  • 考虑突发大小以获得更好的用户体验
  • 监控日志中的速率限制点击次数

发展

设置开发环境

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

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -r requirements.txt

运行测试

pytest tests/

路线图

计划的功能

  • 支持文员MCP和Github MCP
  • 扩展文档
  • TypeScript支持

致谢

______________________________________________________________________

如有任何疑问,请随时提出。

目录标签

目录标签

访问控制Python日志记录research-and-datamathgptmath-solvermath-assistant安全中间件本地部署MCP工具速率限制

接入字段

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

stdio

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

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

4

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdionone部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP