MCP-PIF
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
A JSON-native lambda calculus runtime with metacircular evaluation, designed as an MCP (Model Context Protocol) server. Enables language models to evolve tools dynamically through metaprogramming.
Quick Start
Basic Example
Core Concepts
The Problem
For pure computation language models need computational tools, but existing systems either provide fixed APIs or unrestricted code execution. In the context of metaprogramming and self-modification, neither is ideal. This program presents a middle ground structure for safe, inspectable, evolvable computation.
In the ideal sense, MCP-PIF can be thought of as a generic, metamorphic computer interface where the language model drops-in as an executive function. Here, we provide a simple vocabulary of lambda calculus primitives for access to pure computing only.
The Solution
MCP-PIF provides a lambda calculus with three metaprogramming primitives:
- **quote** - Treat code as data (prevent evaluation)
- **eval** - Execute quoted code dynamically
- **code_of** - Introspect any tool's source code
This creates a **metacircular** system where tools can analyze and transform other tools while maintaining deterministic, fuel-bounded execution. It is homoiconic, but constrained.
It's worth noting quote and eval are not perfectly symmetric:
This prevents eval'd code from inheriting the wrong tool context. When eval executes quoted code:
- **User variables ARE preserved** (lexical scoping maintained)
- **System variables are cleaned** (__tool_name and __self removed to prevent tool context confusion)
- **Tool codes remain available** (for code_of introspection)
- **__eval_depth counter is added** (max depth: 100, prevents infinite eval loops)
The Event Horizon
Because this framework is built in MCP it makes significant compromises in purity. Namely, updating the server code is not part of the metaprogramming loop. This means that the list of primitives, parsing strategies, and the evolution and evaluation processes themselves are not modifiable during runtime.
There are two kinds of tools:
- **MCP tools**: For example creation via evolve (effectful, mutates registry)
- **Evolved tools**: Tool execution via run (pure, functional)
Evolved tools can interact with each other but cannot themselves evolve new tools without the access to the protocol-level tool registry. This "simulacrum" implementation prevents unbounded self-modification by isolating the very invariants which enable the rich metaprogramming.
Language Reference
Core Primitives
| Category | Primitive | JSON Syntax | Description |
|----------|-----------|-------------|-------------|
| **Lambda** | Variable | {"var": "x"} | Variable reference |
| | Function | {"lam": "x", "body": ...} | Lambda abstraction |
| | Application | {"app": {"func": ..., "arg": ...}} | Function application |
| **Arithmetic** | Add | {"add": [a, b]} | Addition |
| | Subtract | {"sub": [a, b]} | Subtraction |
| | Multiply | {"mul": [a, b]} | Multiplication |
| | Divide | {"div": [a, b]} | Division (errors on 0) |
| | Modulo | {"mod": [a, b]} | Modulo (errors on 0) |
| **Comparison** | Equal | {"eq": [a, b]} | Equality test |
| | Less Than | {"lt": [a, b]} | Less than |
| | Less Than or Equal | {"lte": [a, b]} | Less than or equal |
| | Greater Than | {"gt": [a, b]} | Greater than |
| | Greater Than or Equal | {"gte": [a, b]} | Greater than or equal |
| **Logic** | And | {"and": [a, b]} | Logical AND (short-circuit) |
| | Or | {"or": [a, b]} | Logical OR (short-circuit) |
| | Not | {"not": a} | Logical NOT |
| **Control** | If | {"if": {"cond": c, "then": t, "else": e}} | Conditional |
| | Continue | {"continue": {"input": x}} | Recursive step |
| **Lists** | Nil | {"nil": true} | Empty list |
| | Cons | {"cons": {"head": ..., "tail": ...}} | List construction |