Algorithmic AI MCP
An MCP server that exposes 252 algorithms from Knuth's TAOCP to AI agents, with safety guards and structured outputs for tasks like combinatorial generation, SAT solving, number theory, string analysis, graph algorithms, and symbolic math.
README
Algorithmic AI MCP — TAOCP Agent Tools
Computational First-Principles Engine for Autonomous AI Agents
A semantic adapter layer that exposes Donald Knuth's The Art of Computer Programming (TAOCP) algorithms to AI agents like Hermes-Agent, Claude Desktop, and Cursor via Model Context Protocol (MCP).
🎯 What This Is
252 algorithms from Knuth's TAOCP, made agent-accessible through:
- ✅ Tiered Exposure — Only ~30-40 high-value tools exposed (not all 252)
- ✅ Safety Guards — Combinatorial explosion prevention, timeouts, input validation
- ✅ Structured Outputs — Pydantic models for reliable parsing
- ✅ Agent-Optimized UX — "USE WHEN / DO NOT USE" docstrings guide tool selection
- ✅ MCP Portable — Works with Hermes-Agent, Claude Desktop, Cursor, any MCP client
🚀 Quick Start
Installation
pip install taocp-agent-tools
Basic Usage
from taocp_agent_tools import (
generate_permutations,
solve_sat,
modular_exponentiation,
recommend_algorithm,
)
# Example 1: Generate permutations safely
result = generate_permutations([1, 2, 3, 4, 5])
print(f"Generated {result.count} permutations")
# Output: Generated 120 permutations
# Example 2: Solve SAT problem
clauses = [[1, 2, -3], [-1, 3], [2, 3]]
result = solve_sat(clauses, num_variables=3)
print(f"Satisfiable: {result.found}")
# Example 3: Cryptographic computation
result = modular_exponentiation(2, 1000000, 997)
print(f"2^1000000 mod 997 = {result.result}")
# Example 4: Get algorithm recommendation
rec = recommend_algorithm("I need to find all patterns in this DNA sequence")
print(f"Recommended: {rec.recommended}")
print(f"Reason: {rec.reason}")
📦 Available Tools (Tier 1 MVP)
Combinatorics (4 tools)
generate_permutations(items, max_count, derangements_only)— Lexicographic permutations with safety guardsgenerate_combinations(items, k, max_count)— K-combinations generationgenerate_integer_partitions(n, max_count)— Integer partitionsfair_shuffle(items, seed)— Knuth/Fisher-Yates shuffle
Exact Cover / SAT / CSP (3 tools)
solve_exact_cover(rows, columns, max_solutions)— Dancing Links (Algorithm X)solve_sat(clauses, num_variables, find_all)— DPLL SAT solversolve_csp(variables, domains, constraints)— Constraint satisfaction
Number Theory (5 tools)
modular_exponentiation(base, exp, mod)— Binary exponentiationmodular_inverse(a, m)— Extended Euclidean algorithmchinese_remainder(remainders, moduli)— Chinese Remainder Theoremprimality_test(n, rounds)— Miller-Rabin primality testdiscrete_log(base, target, modulus)— Baby-step giant-step
String Analysis (3 tools)
multi_pattern_search(text, patterns)— Aho-Corasick multi-pattern matchingsuffix_tree_query(text, query_type)— Suffix tree queriesburrows_wheeler_transform(text)— BWT for compression
Graph Specialized (3 tools)
bipartite_matching(left, right, edges)— Hopcroft-Karp matchingmax_flow(graph, source, sink)— Ford-Fulkerson max flowstrongly_connected_components(graph)— Tarjan's SCC algorithm
Symbolic Math (3 tools)
symbolic_differentiate(expression, variable, order)— Symbolic differentiationsimplify_expression(expression)— Algebraic simplificationevaluate_symbolic(expression, bindings)— Expression evaluation
Router (1 meta-tool)
recommend_algorithm(task_description, constraints)— Algorithm selection advisor
🛡️ Safety Features
Combinatorial Explosion Prevention
# This will raise TAOCPSafetyError
generate_permutations(list(range(15)))
# Error: Refusing to generate 15! = 1,307,674,368,000 permutations
# This works (with limit)
result = generate_permutations(list(range(15)), max_count=1000)
print(f"Generated {result.count} of 1.3 trillion possible")
Timeout Enforcement
# SAT solving with 30-second timeout
result = solve_sat(large_clauses, num_variables=100)
# If timeout: TAOCPSafetyError with helpful message
Input Validation
# All inputs validated before computation
modular_exponentiation(2, -5, 997)
# Error: exponent must be a positive integer
🔌 MCP Server (Coming Soon)
Make TAOCP tools available to any MCP-compatible agent:
# Install MCP server
pip install taocp-agent-mcp
# Run server
taocp-mcp-server
# Add to Claude Desktop config
{
"mcpServers": {
"taocp": {
"command": "taocp-mcp-server"
}
}
}
📊 Performance
| Tool Category | p50 | p95 | p99 |
|---|---|---|---|
| Combinatorics (n≤10) | 10ms | 50ms | 100ms |
| SAT/CSP (small) | 50ms | 200ms | 500ms |
| Number Theory | 5ms | 20ms | 50ms |
| String Analysis (1MB) | 100ms | 500ms | 1s |
| Graph (100 nodes) | 50ms | 200ms | 500ms |
🧪 Testing
# Install dev dependencies
pip install -e ".[dev]"
# Run unit tests
pytest taocp_agent_tools/tests/ -v --cov=taocp_agent_tools
# Run integration tests
pytest taocp_agent_tools/tests/test_agent_integration.py -v
# Check coverage
coverage report --fail-under=95
📚 Documentation
- PRD — Complete 39-section Product Requirements Document
- Status Report — Implementation status, metrics, next steps
- API Reference — Full API documentation (auto-generated)
🏗️ Architecture
taocp_agent_tools/
├── __init__.py # Public API exports
├── _safety.py # Shared guards & validators
├── _types.py # Pydantic models for structured outputs
├── combinatorics.py # Tier 1: Permutations, combinations, partitions
├── exact_cover.py # Tier 1: DLX, SAT, CSP
├── number_theory.py # Tier 1: Modular arithmetic, primality
├── string_analysis.py # Tier 1: Aho-Corasick, suffix structures, BWT
├── graph_specialized.py # Tier 1: Matching, flow, SCC
├── symbolic_math.py # Tier 1: Differentiation, simplification
├── router.py # Meta-tool: Algorithm selection advisor
└── tests/
├── test_combinatorics.py
├── test_exact_cover.py
├── test_number_theory.py
├── test_string_analysis.py
├── test_graph.py
├── test_symbolic.py
├── test_router.py
└── test_agent_integration.py
🎓 When to Use TAOCP Tools
✅ Use TAOCP Tools When:
- You need exhaustive combinatorial generation (permutations, combinations, partitions)
- Solving constraint satisfaction problems (Sudoku, scheduling, puzzles)
- Performing cryptographic computations (modular exponentiation, primality testing)
- Multi-pattern search in large texts (DNA sequences, virus scanning)
- Specialized graph algorithms (bipartite matching, max flow, SCC)
- Symbolic mathematics (differentiation, simplification)
❌ Use Python Stdlib When:
- Basic sorting (
sorted(),list.sort()) - Basic searching (
bisect,inoperator) - Simple randomization (
random.shuffle,random.sample) - Basic math (
math.factorial,math.comb)
🤝 Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
git clone https://github.com/ksjpswaroop/algorithmic-ai-mcp.git
cd algorithmic-ai-mcp
pip install -e ".[dev]"
pre-commit install
📄 License
Distributed under the MIT License. See LICENSE for more information.
🙏 Acknowledgments
- Donald Knuth for The Art of Computer Programming — the foundation of this library
- TAOCP SDK — Core algorithm implementations
- Hermes-Agent — Primary integration target and testing ground
- MCP Foundation — Model Context Protocol for agent tool standardization
📬 Contact
- Author: Swaroop (ksjpswaroop@gmail.com)
- Repository: https://github.com/ksjpswaroop/algorithmic-ai-mcp
- TAOCP SDK: https://github.com/ksjpswaroop/taocp-complete
🚀 Roadmap
v1.0 (MVP) — Q4 2026
- ✅ 15 Tier 1 tools implemented
- ✅ Safety guards on all tools
- ✅ Integration tests with >90% accuracy
- ⏳ PyPI publication
- ⏳ MCP server packaging
v1.1 — Q1 2027
- String analysis tools (Aho-Corasick, suffix trees, BWT)
- Graph specialized tools (matching, flow, SCC)
- Symbolic math tools (differentiation, simplification)
- Documentation site
v2.0 — Q2 2027
- Tier 2 internal utilities
- Advanced routing (ML-based tool selection)
- Caching layer for repeated computations
- Rate limiting for shared deployments
- Streaming outputs for large generators
Built with ❤️ for the AI agent ecosystem
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。