🏛️ PAS-科学推理MCP服务器
P侧 • A.ristotle• Socrates
一种模型上下文协议(MCP)服务器,为人工智能代理带来结构化的贝叶斯推理。PAS实现了一个以科学法律为基础的思想之树架构,使人工智能能够通过复杂的问题进行更深思熟虑的推理。
   ](CHANGELOG.md)
______________________________________________________________________
🎯 什么是PAS?
PAS通过以下方式改变了AI代理处理复杂推理的方式:
- 扩展 系统的假设(如柏拉图的构思)
- 批评 每个分支都有反驳(如苏格拉底的辩证法)
- 接地 科学定律中的推理(如亚里士多德的经验主义)
PAS构建了一个 推理树 其中每个假设都使用贝叶斯推理进行评分,并通过对抗性批评进行质疑。
______________________________________________________________________
✨ 特性
| 特性 | 描述 |
|---|---|
| 贝叶斯思想树 | 利用后验概率评分构建推理树 |
| 科学法基础 | 15+定律(CAP定理、奥卡姆剃刀等)通知先验 |
| 质量门 | 0.9分+0.1分差距阈值及改进建议 |
| 负空间批判 | 找出缺失的东西,而不仅仅是问题所在 |
| 智能面试模式 | 基于心理学的问答,收集缺失的上下文 |
| 域检测 | 为定制问题自动检测问题域 |
| RLVR自学 | 从终端输出自动检测成功/失败 |
| 顺序间隙分析 | 逐层对抗间隙检测(v32/v37) |
| 会话标记 | 使用标签组织会话以供检索 |
| 持久特征 | 了解会话中的用户偏好(v22) |
| 过往故障表面处理 | 在批评过程中从过去的类似失败中吸取教训 |
| 实时代码导航 | 通过Jedi(v38)查找参考文献/定义 |
| 符号建议 | 在假设生成过程中自动建议符号 |
| 飞行前执法 | 假设储存时的结构护栏(v41) |
| 自我意识 | PAS可以反思自己的模式/工具/架构(v40) |
| 自我意识测试套件 | 将故障记录回PAS的4层测试(v42) |
______________________________________________________________________
🧠 顺序思维整合
PAS旨在协同工作 @anthropic/mcp-sequential-thinking.虽然顺序思维处理 线性 PAS提供的思维链 树状结构的 使用贝叶斯评分进行推理。
补充用途
| 方面 | 顺序思维 | PAS |
|---|---|---|
| 结构 | 线性链 | 贝叶斯树 |
| 评分 | 无 | 先验×可能性=后验 |
| 自我批评 | 无 | 分级处罚(重大/轻微缺陷) |
| 质量门 | 无 | 0.9分,差0.1分 |
| 自学 | 无 | 定律+失败记忆+特质 |
| 输出 | 最终想法 | 排名推荐+差距 |
推荐图案
1. Use Sequential Thinking for quick, linear reasoning
2. When uncertainty is high, escalate to PAS:
→ start_reasoning_session(user_goal="...")
→ Expand, critique, deepen until quality gate passes
3. Record outcome for RLVR learning______________________________________________________________________
🛠️ 工具(总计25+)
会话管理
| 工具 | 说明 |
|---|---|
start_reasoning_session | 以目标开始新的推理会话 |
get_session_status | 检查会话状态和思考次数 |
find_or_create_session | 智能路由器-查找现有会话或创建新会话 |
complete_session | 明确关闭会话 |
resume_session | 使用继承继续已完成的会话 |
tag_session | 为组织添加标签 |
推理(扩展与批判)
| 工具 | 说明 |
|---|---|
prepare_expansion | 获取上下文+相关定律以生成假设 |
store_expansion | 使用贝叶斯评分存储1-3个假设 |
prepare_critique | 获取节点上下文+LLM反参数提示 |
store_critique | 分级处罚的店铺评价(主要/次要) |
search_relevant_laws | 通过语义相似性发现科学规律 |
顺序分析(v32/v37)
| 工具 | 说明 |
|---|---|
prepare_sequential_analysis | 获得对顶尖候选人进行5层差距分析的提示 |
store_sequential_analysis | 存储差距分析,检测系统差距 |
5层间隙分析 检查:
- 代码结构 -需要哪些代码更改?
- 依赖项 -假设了哪些包/系统?
- 数据流 -哪些数据会移动到哪里?
- 接口 -哪些API/合约受到影响?
- 工作流 -用户/系统流程发生了哪些变化?
树导航
| 工具 | 说明 |
|---|---|
get_reasoning_tree | 查看带有分数的完整树结构 |
get_best_path | 找到得分最高的推理路径 |
finalize_session | 自动评论、质量门、退货推荐 |
聪明面试
| 工具 | 说明 |
|---|---|
identify_gaps | 根据目标生成澄清问题 |
get_next_question | 使用格式化选项一次回答一个问题 |
submit_answer | 回答问题,触发后续规则 |
check_interview_complete | 检查是否收集了足够的上下文 |
面试特点:
- 域检测 -自动检测UI、架构、调试、测试域
- 隐藏上下文 -选择包含用于特征推理的隐藏元数据
- 后续规则 -基于答案的条件问题注入
- 进度跟踪 -最多15个问题,3级深度
- 历史档案 -为自学而存储的已回答问题
自主学习(RLVR)
| 工具 | 说明 |
|---|---|
record_outcome | 用语义归因记录成功/失败 |
parse_terminal_output | 自动检测来自终端的成功/失败信号 |
refresh_law_weights | 根据结果更新法律权重 |
log_conversation | 存储用户输入以进行语义搜索 |
search_conversation_log | 通过相似性查找过去的上下文 |
RLVR自动录制:
{
"finalize_session": {
"terminal_output": "[terminal logs here]",
"auto_record": true
}
}PAS自动解析终端输出并记录结果。
代码导航(v38)
| 工具 | 说明 |
|---|---|
sync_project | 为项目建立索引以进行符号搜索 |
query_codebase | 索引文件的语义搜索 |
find_references | 查找所有对符号的引用(现场绝地武士) |
go_to_definition | 跳转到符号定义 |
call_hierarchy | 构建调用者/被调用者树 |
import_lsif | 导入LSIF索引(可选回退) |
______________________________________________________________________
📦 安装
先决条件
- Python 3.10+
- PostgreSQL 16+及其扩展:
- pgvector (语义相似性) - ltree (树路径)
步骤1:克隆和设置
git clone https://github.com/nocountryman/mcp-pas.git
cd mcp-pas
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt依赖项
| 包装 | 版本 | 用途 |
|---|---|---|
mcp | 最新 | 模型上下文协议服务器框架 |
psycopg2-binary | 最新 | PostgreSQL适配器 |
pgvector | 最新 | 嵌入的向量相似性 |
pydantic | 最新 | 数据验证 |
numpy | 最新 | 数值运算 |
sentence-transformers | 最新 | 本地嵌入(全MiniLM-L6-v2) |
tree-sitter-language-pack | ≥0.13.0 | 用于代码索引的符号提取 |
pyyaml | ≥6.0 | 配置文件解析 |
jedi | 最新 | 生活 代码导航(查找引用,转到定义) |
可选工具
| 工具 | 安装 | 目的 |
|---|---|---|
pyright | pip install pyright | 为生成LSIF索引 精确 代码导航 |
何时使用LSIF vs Jedi:
- 绝地武士 (默认):实时分析,无需预索引,开箱即用
- 生命科学创新论坛 (可选):通过预先计算的指数
pyright --outputtype lsif,对于大型代码库更快
# Generate LSIF index (optional)
pyright --outputtype lsif --outputfile project.lsif.json
# Import into PAS
# → import_lsif(project_id="...", lsif_path="/path/to/project.lsif.json")步骤2:数据库设置
# Create database
sudo -u postgres createdb mcp_pas
# Enable extensions
sudo -u postgres psql -d mcp_pas -c "CREATE EXTENSION IF NOT EXISTS vector;"
sudo -u postgres psql -d mcp_pas -c "CREATE EXTENSION IF NOT EXISTS ltree;"
# Run schema
psql -d mcp_pas -f schema.sql
# Seed scientific laws and domains
python seed_laws.py
python seed_domains_v2.py步骤3:环境配置
cp env.template .env
# Edit .env with your database credentialsDATABASE_URL=postgresql://user:password@localhost:5432/mcp_pas注: PAS通过以下方式使用本地嵌入 sentence-transformers 默认情况下。不需要OpenAI API密钥。步骤4:GPU加速(可选)
PAS嵌入模型可以在GPU上运行 加载速度提高5-10倍 (CPU上为11秒vs 2-5分钟)。
AMD GPU(ROCm)
注: ROCm-PyTorch轮子需要Python 3.10-3.12。在使用Python 3.14+的滚动发布发行版(Arch/CachyOS)上,您需要一个单独的Python 3.12虚拟环境。
第一步:使用ROCm-PyTorch创建Python 3.12 venv:
# Create separate venv with Python 3.12
python3.12 -m venv .venv312
source .venv312/bin/activate
# Install ROCm PyTorch from official wheels
pip install torch --index-url https://download.pytorch.org/whl/rocm6.2
# Install other dependencies
pip install -r requirements.txt步骤2:RDNA2 GPU解决方法(RX 6000系列):
RDNA2 GPU(gfx1032、gfx1030)需要一个环境变量覆盖:
export HSA_OVERRIDE_GFX_VERSION=10.3.0将此添加到您的MCP配置中:
{
"env": {
"DATABASE_URL": "...",
"HSA_OVERRIDE_GFX_VERSION": "10.3.0"
}
}验证是否检测到GPU:
source .venv312/bin/activate
HSA_OVERRIDE_GFX_VERSION=10.3.0 python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"
# Expected: True AMD Radeon RX 6650 XT (or your GPU)NVIDIA GPU(CUDA)
开 Arch Linux/CachyOS:
sudo pacman -S python-pytorch-cuda cuda cudnn开 Ubuntu/Debian:
pip install torch --index-url https://download.pytorch.org/whl/cu121性能比较
| 度量 | CPU | GPU(ROCm/CUDA) |
|---|---|---|
| 模型加载 | 2-5分钟 | 11-30秒 |
| 对100个文本进行编码 | ~500ms | ~50ms |
| 已用内存 | 系统RAM | VRAM |
无需其他更改 -一旦venv使用ROCm/CUDA火炬,单例 utils.py 自动将模型加载到GPU。
______________________________________________________________________
🔌 IDE集成
VS代码/光标(带Claude/Gemini扩展名)
添加到MCP配置中:
{
"mcpServers": {
"pas-server": {
"command": "/path/to/mcp-pas/.venv/bin/python",
"args": ["/path/to/mcp-pas/server.py"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mcp_pas",
"HSA_OVERRIDE_GFX_VERSION": "10.3.0"
}
}
}
}注: 使用.venv312/bin/python适用于GPU(ROCm)或.venv/bin/python仅适用于CPU。 移除HSA_OVERRIDE_GFX_VERSION如果使用NVIDIA或RDNA3+GPU。
配置后:重新启动IDE(Ctrl+Shift+P → 重新加载窗口)。
______________________________________________________________________
🚀 用法详解
基本推理流程
1. Start session
→ start_reasoning_session(user_goal="Design a caching layer")
2. Expand hypotheses (3 alternatives)
→ prepare_expansion(session_id="...")
→ store_expansion(session_id="...", h1_text="...", h1_confidence=0.85, ...)
3. Critique top hypothesis
→ prepare_critique(node_id="...") # Returns llm_prompt
→ [Process prompt]
→ store_critique(node_id="...", counterargument="...", severity_score=0.3)
4. Sequential gap analysis (REQUIRED before finalize)
→ prepare_sequential_analysis(session_id="...", top_n=3)
→ [Process 5-layer prompts]
→ store_sequential_analysis(session_id="...", results="[...]")
5. Deepen if score < 0.9 or gap < 0.1
→ store_expansion(parent_node_id="...", h1_text="Improved approach...", h1_confidence=0.95)
6. Get recommendation
→ finalize_session(session_id="...")
# Returns: quality_gate, recommendation, exhaustive_check智能面试流程
1. Identify missing context
→ identify_gaps(session_id="...")
2. Ask questions one at a time
→ get_next_question(session_id="...")
→ [Present to user]
→ submit_answer(session_id="...", question_id="...", answer="B")
3. Check completion
→ check_interview_complete(session_id="...")
# Once complete, hidden context is propagated to session质量门(v31)
PAS不会接受低质量的决策:
{
"quality_gate": {
"score": 0.95,
"score_threshold": 0.9,
"score_ok": true,
"gap": 0.12,
"gap_threshold": 0.1,
"gap_ok": true,
"passed": true
}
}如果 passed: false,PAS建议如何改进:
{
"score_improvement_suggestions": [
{"lever": "score", "action": "Expand deeper with higher confidence (0.9+)"},
{"lever": "gap", "action": "Explore more diverse alternatives"}
]
}______________________________________________________________________
📊 建筑
模块结构(v42)
server.py Main MCP server (~5400 lines)
├── errors.py Exception hierarchy (~200 lines)
├── utils.py DB, embeddings, validation (~185 lines)
├── reasoning_helpers.py Bayesian scoring, quality (~310 lines)
├── learning_helpers.py RLVR, terminal parsing (~240 lines)
├── interview_helpers.py Interview flow (~220 lines)
├── codebase_helpers.py Symbol extraction (~260 lines)
├── sessions_helpers.py Session lifecycle (~270 lines)
├── metacognitive_helpers.py 5-stage prompting (~200 lines)
├── preflight_helpers.py Preflight enforcement (~180 lines)
├── calibration_helpers.py CSR calibration (~180 lines)
├── purpose_helpers.py Hierarchical inference (~150 lines)
├── hybrid_helpers.py Hypothesis synthesis (~120 lines)
└── self_awareness_helpers.py Schema introspection (~250 lines)
tests/
├── conftest.py Fixtures + Layer 4 failure logging
├── test_tools/ Layer 1: Static domain tests
│ ├── test_reasoning.py 16 tests (9 tools)
│ ├── test_learning.py 6 tests (4 tools)
│ ├── test_codebase.py 8 tests (8 tools)
│ ├── test_metacognitive.py 7 tests (3 tools)
│ └── test_interview.py 5 tests (4 tools)
├── scenarios/ Layer 2: YAML workflow tests
├── test_scenarios.py YAML runner
├── test_coverage.py Layer 3: Self-aware coverage
└── test_server.py Legacy v22/v23 tests数据库表
| 表 | 目的 |
|---|---|
reasoning_sessions | 会话状态、目标、上下文 |
thought_nodes | 具有贝叶斯分数的假设树 |
critique_results | 反驳和处罚 |
scientific_laws | 有重量的接地法 |
outcome_records | 学习的成功/失败 |
user_trait_profiles | 持久用户偏好 |
interview_history | 存档的学习问答 |
file_registry | 已索引的项目文件 |
file_symbols | 提取的符号 |
lsif_references | LSIF索引数据 |
______________________________________________________________________
📚 科学法律图书馆
PAS包括15条以上既定的推理法则:
- CAP定理 -分布式系统的权衡
- 奥卡姆剃刀 -更喜欢简单的解决方案
- 康威定律 -系统结构反映组织
- 海勒姆定律 -所有可观察到的行为都将取决于
- 布鲁克斯定律 -将人员添加到后期项目会使他们更晚
- 阿姆达尔定律 -并行加速限制
- 侯世达定律 -它总是比预期的要花更长的时间
- *…以及更多*
______________________________________________________________________
🧪 测试
PAS包括 自我意识测试套件 它测试自己,并将发现的错误记录回PAS进行学习。
测试套件架构(v42)
| 图层 | 目的 | 文件 |
|---|---|---|
| 层1 | 38个工具的静态单元测试 | tests/test_tools/*.py |
| 层2 | YAML定义的工作流场景 | tests/scenarios/*.yaml |
| 层3 | 有自我意识的报道记者 | tests/test_coverage.py |
| 第4层 | PAS故障记录 | tests/conftest.py 钩子 |
运行测试
# Full suite with PAS failure logging
PAS_DB_NAME=mcp_pas pytest tests/ -v
# Fast mode (no failure logging)
PAS_DB_NAME=mcp_pas PAS_LOG_FAILURES=false pytest tests/ -v
# Run only unit tests
PAS_DB_NAME=mcp_pas pytest tests/test_tools/ -v
# Run YAML scenarios
PAS_DB_NAME=mcp_pas pytest tests/test_scenarios.py -v
# Check coverage (fails if new tool lacks tests)
PAS_DB_NAME=mcp_pas pytest tests/test_coverage.py -v自我意识覆盖
当添加新工具时, test_coverage.py 自动失败:
Missing tests for: [new_tool_name]这确保了测试覆盖率随着代码库的增长而增长。
______________________________________________________________________
🤖 模型兼容性
| 型号 | 状态 |
|---|---|
| 克劳德作品4.5 | ✅ 作品 |
| 克劳德·十四行诗4.5✅ 作品 | |
| 双子座3闪光✅ 作品 | |
| 双子座3 Pro⚠️ 工具调用格式问题 |
______________________________________________________________________
📈 更新日志
看 更改日志.md 版本历史。
当前版本: v42测试
______________________________________________________________________
🤝 贡献
欢迎投稿!感兴趣的领域:
- 附加科学定律
- 新的推理模式
- 特定领域的问题集
- 性能优化
______________________________________________________________________
📄 许可证
GNU AGPLv3许可证-请参阅 许可证 了解详情。
______________________________________________________________________
🙏 致谢
以西方哲学的三大支柱命名:
- 柏拉图 -构思和假设生成
- 亚里士多德 -科学规律的经验基础
- 苏格拉底 -辩证批判与质疑
*“未经检验的想法不值得相信。”*
