MCP TypeScript Implementation
A TypeScript implementation of the Model Context Protocol for the Personal Intelligence Framework.
MCP-PIF-CLJS: A Self-Modifying MCP Server with Formal Reasoning
A Model Context Protocol (MCP) server written in ClojureScript that explores homoiconicity, formal reasoning, and metaprogramming to enable runtime tool creation and safe self-modification capabilities. It allows models like Claude to create and execute new tools during runtime, evaluate lambda calculus expressions, perform type inference, and prove logical theoremsβall without restarting the server.
This project combines Clojure's code-as-data philosophy with formal methods, providing a unique platform for exploring self-verifying code, type-driven development, and automated reasoning within an AI-assisted environment.
π Quick Start
Prerequisites
- Node.js 16+
- Java 11+ (for ClojureScript compiler)
Installation
-
Clone and build:
git clone <repository-url> cd MCP-PIF npm install npx shadow-cljs compile mcp-server
-
Configure Claude Desktop:
Edit your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "mcp-pif-cljs": { "command": "node", "args": ["/full/path/to/MCP-PIF/out/mcp-server.js"] } } }
- macOS:
-
Restart Claude Desktop
Building a .dxt Package
For easier use and distribution, you can create a .dxt package:
./package-dxt.sh
This creates mcp-pif-cljs.dxt
which can be installed via drag-and-drop in Claude Desktop.
π οΈ Available Tools
Base Tools
memory-store
- Store key-value pairs in memorymemory-retrieve
- Retrieve stored valuesjournal-recent
- View recent activity journalserver-info
- Get comprehensive server information (all tools, state, statistics)
Meta-Programming Tools
meta-evolve
- Create new tools at runtime (arithmetic, string, lambda, typed)execute-tool
- Execute any tool by name (including dynamic ones)
Formal Reasoning Tools
lambda-eval
- Evaluate lambda calculus expressions with beta reductiontype-check
- Perform Hindley-Milner type inference on expressionsprove
- Automated theorem proving for propositional logic
π‘ Example Usage
Basic Memory Storage
You: "Store my favorite programming language as ClojureScript"
Claude: I'll store that for you using the memory-store tool.
You: "What's my favorite programming language?"
Claude: Your favorite programming language is ClojureScript.
Creating Custom Tools
You: "I need a tool that calculates the area of a circle"
Claude: I'll create that tool for you using meta-evolve...
[Creates tool with code: (args) => Math.PI * args.radius * args.radius]
You: "What's the area of a circle with radius 5?"
Claude: The area is 78.54 square units.
Lambda Calculus & Formal Reasoning
You: "Evaluate the lambda expression for identity function applied to 42"
Claude: Using lambda-eval with expression: [(Ξ» x x) 42]
Result: 42 (reduced in 1 step)
You: "What's the type of function composition?"
Claude: Using type-check on (Ξ» f (Ξ» g (Ξ» x [g [f x]])))
Type: ((a β b) β ((b β c) β (a β c)))
You: "Prove that if A implies B and we have A, then B follows"
Claude: Using the prove tool with modus ponens...
Proof found! B is derived from premises A and AβB.
The Dynamic Tool Workflow
Due to MCP client caching, newly created tools must be called via execute-tool
:
-
Create a tool:
Use meta-evolve to create "multiply": - code: "(args) => args.x * args.y" - tool-type: "arithmetic"
-
Verify creation:
Use server-info (You'll see "multiply [RUNTIME]" in the tools list)
-
Execute the tool:
Use execute-tool with: - tool-name: "multiply" - arguments: { x: 6, y: 7 } Result: 42
ποΈ Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β AI Client ββββββΆβ MCP Protocol ββββββΆβ Meta Engine β
β (Claude) β β (stdio/jsonrpc) β β (Self-Modifier) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββ
β Tools/Memory β β Journal DB β
β (Extensible) β β (DataScript) β
ββββββββββββββββββββ βββββββββββββββββββ
Project Structure
src/mcp/
βββ core.cljs # Main server & request routing
βββ protocol.cljs # JSON-RPC/MCP protocol handling
βββ tools.cljs # Tool definitions and handlers
βββ meta.cljs # Self-modification engine
βββ evaluator.cljs # Safe JavaScript evaluation
βββ journal.cljs # Activity logging (DataScript)
βββ lambda.cljs # Lambda calculus evaluator
βββ types.cljs # Hindley-Milner type inference
βββ proof.cljs # Automated theorem proving
π Safety Mechanisms
- Sandboxed Execution: Limited to arithmetic and string operations
- Code Validation: Blocks dangerous operations (file system, network, process)
- Namespace Protection: Core namespaces cannot be modified
- Activity Journal: All actions are logged and auditable
- Session-Only: Changes don't persist between restarts
π§ͺ Development
# Development build with hot reload
npx shadow-cljs watch mcp-server
# Run tests
npm test
# Create .dxt package
./package-dxt.sh
Testing the Server
# Basic protocol test
node test-clean-protocol.js
# Dynamic tools test
node test-dynamic-tools.js
# Formal reasoning test
node test-formal-reasoning.js
π― Philosophy
This project explores the intersection of:
- Homoiconicity: Code as data, data as code
- Self-Reference: A system that can reason about itself
- Controlled Evolution: Safe boundaries for self-modification
- Formal Methods: Type systems and proof checking for verified computation
- Human-AI Collaboration: AI proposes, human uses
π Roadmap
Completed:
- Basic MCP server in ClojureScript
- Runtime tool creation
- Universal tool executor (workaround for client caching)
- .dxt packaging support
- Lambda calculus evaluator with Church encodings
- Hindley-Milner type inference system
- Automated theorem proving for propositional logic
In progress:
- Tool composition (tools that use other tools)
- Namespace evolution
- Import capabilities from other MCP servers
- Persistent tool storage
- Dependent type system
- SMT solver integration
- Self-verifying tool creation
β οΈ Important Notes
- Tool Persistence: Tools only exist while server is running
- Client Caching: Use
execute-tool
to call runtime-created tools - Real Computation: Tools execute actual code, not LLM approximations
- Experimental Server: Work in progress, tools may not work as expected
π€ Contributing
This is an experimental project exploring metaprogramming in the context of AI tools. Contributions that enhance self-modification capabilities or improve safety are welcome!
π License
MIT
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." - Einstein
This project asks: What if our tools could evolve their own thinking?
Related Servers
Ghibli Video
Generates AI images and videos using the GPT4O Image Generator API.
Azure DevOps MCP Server
An MCP server for Azure DevOps, enabling AI assistants to interact with Azure DevOps APIs.
MCP System Monitor Server
A cross-platform server for real-time monitoring of CPU, GPU, memory, disk, network, and process information.
FastMCP
A TypeScript framework for building MCP servers with client session handling.
Buildable
Official MCP server for Buildable AI-powered development platform. Enables AI assistants to manage tasks, track progress, get project context, and collaborate with humans on software projects.
Nextflow Developer Tools
An MCP server for Nextflow development and testing, which requires a local clone of the Nextflow Git repository.
Terraform MCP Server
Integrates with Terraform Registry APIs for Infrastructure as Code development, supporting provider and module discovery.
Laravel Codebase Introspection
Introspects Laravel codebases to provide structured information about views, routes, classes, and models using the mateffy/laravel-introspect package.
ALAPI
ALAPI MCP Tools,Call hundreds of API interfaces via MCP
Vibe-Coder
A server for a structured, LLM-based coding workflow, from feature clarification and planning to phased development and progress tracking.