使用说明
mcp指令服务器
Python中的最小、生产就绪的模型上下文协议(MCP)服务器,为任何支持MCP的AI应用程序提供规范指令。
安装
请确保您已安装Python 3.10+。然后安装软件包:
pip install -e .
或者直接使用pip:
pip install .
运行服务器
发展模式
python -m mcp_instructions_server.server
或者使用开发脚本(安装后):
dev
生产模式
start
开发脚本
dev-在开发模式下运行服务器start-以生产模式启动服务器lint-使用ruff进行掉毛检查format-使用ruff格式化程序格式化代码
MCP客户端使用示例
获取提示
服务器提供三个提示:
- 安全 -实施最低权限和安全最佳实践的安全说明
- rai_guidance -负责任的人工智能(RAI)对道德人工智能实践的指导
- all_说明 -安全和RAI综合指导说明
使用MCP客户端的示例:
# Example: Fetching the security prompt
# The client would call the MCP prompt API to get:
# {
# "role": "system",
# "content": "Enforce least privilege, redact secrets, refuse exploit/abuse content, validate untrusted inputs, prefer most restrictive rule on conflict."
# }
获取资源
服务器公开了一个资源:
- instructions://canonical -Markdown格式的完整规范说明
例子:
# The client would call the MCP resource API to fetch:
# URI: instructions://canonical
# MIME Type: text/markdown
# Content: Markdown with version header and both Security and RAI Guidance sections
健康检查工具
服务器提供 health_check 返回服务器状态的工具:
# Example response:
{
"status": "ok",
"serverTime": "2024-01-01T12:00:00.000000Z"
}
光标配置示例
整合 mcp-instructions-server 使用Cursor,将以下内容添加到您的Cursor配置中:
{
"mcpServers": {
"instructions": {
"command": "python",
"args": ["-m", "mcp_instructions_server.server"]
}
}
}
备注:根据需要调整Python的路径。如果您已在虚拟环境中安装了该包,则可能需要使用Python可执行文件的完整路径。
验收
提示面板
验证提示面板是否显示:
securityrai_guidanceall_instructions
资源提取
确保获取 instructions://canonical 资源返回:
- Markdown内容包含安全和RAI指导部分
- 版本标头:
# Instructions Version v1.0.0
健康检查
确认通话 health_check 返回:
{"status": "ok", "serverTime": "<ISO8601>"}
项目结构
mcp_instructions_server/
├── __init__.py # Package initialization
├── server.py # Main entrypoint; registers prompts, resources, tools
├── instructions.py # Stores versioned instruction text
├── prompts.py # Wires MCP prompts
├── resources.py # Wires MCP resources
└── tools.py # Defines health_check tool
质量保证
- 代码质量:干净、文档齐全的代码,没有TODO
- 类型提示:贯穿全文的完整类型注释
- 日志记录:具有优雅关机处理的结构化日志记录
- 代码检查:运行
lint检查代码质量 - 格式化:运行
format格式化代码
更新说明
要更新指令内容,请编辑 mcp_instructions_server/instructions.py:
- 更新
INSTRUCTIONS_VERSION根据需要 - 修改
SECURITY_INSTRUCTION安全指南 - 修改
RAI_GUIDANCERAI指南 - 这
ALL_INSTRUCTIONS_MD将自动包括这两个部分
许可证
麻省理工学院