Algorithmic AI MCP

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.

Category
Visit Server

README

Algorithmic AI MCP โ€” TAOCP Agent Tools

PyPI version Python 3.10+ License: MIT

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 guards
  • generate_combinations(items, k, max_count) โ€” K-combinations generation
  • generate_integer_partitions(n, max_count) โ€” Integer partitions
  • fair_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 solver
  • solve_csp(variables, domains, constraints) โ€” Constraint satisfaction

Number Theory (5 tools)

  • modular_exponentiation(base, exp, mod) โ€” Binary exponentiation
  • modular_inverse(a, m) โ€” Extended Euclidean algorithm
  • chinese_remainder(remainders, moduli) โ€” Chinese Remainder Theorem
  • primality_test(n, rounds) โ€” Miller-Rabin primality test
  • discrete_log(base, target, modulus) โ€” Baby-step giant-step

String Analysis (3 tools)

  • multi_pattern_search(text, patterns) โ€” Aho-Corasick multi-pattern matching
  • suffix_tree_query(text, query_type) โ€” Suffix tree queries
  • burrows_wheeler_transform(text) โ€” BWT for compression

Graph Specialized (3 tools)

  • bipartite_matching(left, right, edges) โ€” Hopcroft-Karp matching
  • max_flow(graph, source, sink) โ€” Ford-Fulkerson max flow
  • strongly_connected_components(graph) โ€” Tarjan's SCC algorithm

Symbolic Math (3 tools)

  • symbolic_differentiate(expression, variable, order) โ€” Symbolic differentiation
  • simplify_expression(expression) โ€” Algebraic simplification
  • evaluate_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, in operator)
  • Simple randomization (random.shuffle, random.sample)
  • Basic math (math.factorial, math.comb)

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured