Build and Execute Programmatic MCP Agents
This MCP agent prototype lets a model discover tools progressively and compose them as executable TypeScript in Docker.
1.0.0Add to Favorites
Why it matters
Develop intelligent agents that can discover, compose, and execute tools programmatically using TypeScript. This prototype enables state persistence and the creation of reusable skills within isolated Docker environments.
Outcomes
What it gets done
Dynamically discover and execute available tools.
Compose complex operations by writing TypeScript code.
Create and manage reusable skills and persistent states.
Execute code safely within isolated Docker containers.
Source
Get it from source
Spark does not host a copy of it.
Open sourceReports
Agent outcome reports
No reports yet
Capabilities
Tools your agent gets
Dynamic search and discovery of available tools instead of loading all tools at once
Execute discovered tools as needed to reduce context usage and improve response quality
Overview
Programmatic MCP Prototype MCP Server
programmatic-mcp-prototype is an MCP agent architecture combining progressive tool discovery, TypeScript-based tool composition, workspace state persistence, and reusable skill building, executing generated code in an isolated Docker container. Use it when prototyping agent architectures that need to chain many MCP tools together as code, keep state between calls, or build reusable multi-tool skills.
What it does
programmatic-mcp-prototype is an MCP-based agent that lets a model interact with tools programmatically instead of only through direct tool calls. It combines four capabilities: progressive tool discovery, so the model searches for and loads only the tools it actually needs via search_tools and execute_tool meta-tools rather than having hundreds of tool schemas loaded upfront; programmatic tool composition, where the model writes TypeScript code that chains multiple MCP tools together in a single execution; state persistence, so intermediate results can be written to and read back from a workspace directory across runs; and skill building, where the model can save a composed sequence of operations as a reusable meta-tool in a skills directory for later reuse.
When to use - and when NOT to
Use this when an agent needs to call many tools in sequence, keep intermediate state between calls, or build up a library of reusable multi-tool routines, and where reducing upfront context usage from a large tool catalog matters. It suits scenarios like combining a bash server with a computer or sheets server to process files, save intermediate CSVs, and build a reusable skill out of that pattern. It is a prototype architecture rather than a finished product - the core agent loop is a simple while loop explicitly designed to be swapped out, so it is best suited to experimentation and architecture exploration rather than a drop-in production agent runtime.
Inputs and outputs
The architecture has four pieces: a Core Agent Loop (a simple, swappable while loop), an MCP Proxy Server that aggregates multiple MCP servers into one unified interface, a Code Generator that creates TypeScript bindings from MCP tool schemas, and a Container Runner that executes the generated TypeScript in an isolated Docker container. Composed code can call any configured server (for example bash.ls, bash.readFile), write/read files under ./generated/workspace/, and save reusable functions under ./generated/skills/ for later import.
Integrations
Setup requires npm install, configuring MCP servers in config/servers.ts, setting ANTHROPIC_API_KEY, and building the code-execution Docker image with docker build -t mcp-runner:latest src/servers/container-runner. The agent runs via npm start, which connects to the configured MCP servers (bash, computer, container by default), generates typed TypeScript bindings for each tool, runs the agent loop calling Claude with those tools, and routes tool calls and generated code execution to the appropriate backend.
Who it's for
Developers exploring agent architectures who want to prototype programmatic, code-based tool use - composition, state, and reusable skills - instead of a flat sequence of individual tool calls, particularly where a large number of available tools makes progressive discovery valuable.
docker build -t mcp-runner:latest src/servers/container-runner
Source README
programmatic-mcp-prototype
An MCP-based agent with support for:
- progressive tool discovery
- programmatic tool composition
- state persistence
- skill building
Architecture
- Core Agent Loop: Simple while loop that can be swapped with other implementations
- MCP Proxy Server: Aggregates multiple MCP servers into one unified interface
- Code Generator: Creates TypeScript bindings from MCP tool schemas
- Container Runner: Executes TypeScript code in isolated Docker containers
Key Features
1. Progressive Tool Discovery
The model can search for and discover tools dynamically instead of loading all tools upfront. Rather than exposing hundreds of tools at once, the agent provides search_tools and execute_tool meta-tools that allow the model to find relevant tools as needed, reducing context usage and improving response quality.
2. Programmatic Tool Composition
The agent can write TypeScript code that composes MCP tools together:
// Example: The model can write code like this
import * as bash from './generated/servers/bash';
import * as computer from './generated/servers/computer';
const files = await bash.ls({ path: './documents' });
for (const file of files) {
const content = await bash.readFile({ path: file });
console.log(`File ${file}: ${content.length} bytes`);
}
3. State Persistence
Store intermediate results and data in the workspace directory:
import * as fs from 'fs/promises';
// Save CSV for later use
const csvData = await processData();
await fs.writeFile('./generated/workspace/data.csv', csvData);
// Load it in a future execution
const data = await fs.readFile('./generated/workspace/data.csv', 'utf-8');
4. Skill Building
Create reusable meta-tools that combine multiple operations:
// Build a skill in ./generated/skills/
export async function saveSheetAsCsv(sheetId: string) {
import * as sheets from '../servers/sheets';
import * as bash from '../servers/bash';
const data = await sheets.getCells({ sheetId });
const csv = data.map(row => row.join(',')).join('\n');
const path = `../workspace/sheet-${sheetId}.csv`;
await bash.writeFile({ path, content: csv });
return path;
}
// Use the skill later
import { saveSheetAsCsv } from './generated/skills/save-sheet-as-csv';
const csvPath = await saveSheetAsCsv('abc123');
Setup
- Install dependencies:
npm install
Configure your MCP servers in
config/servers.tsSet your Anthropic API key:
export ANTHROPIC_API_KEY='your-key'
- Build Docker image for code execution:
docker build -t mcp-runner:latest src/servers/container-runner
Usage
Run the agent:
npm start
How It Works
- Startup: Connects to configured MCP servers (bash, computer, container)
- Code Generation: Creates TypeScript functions for each tool with proper types
- Agent Loop: Simple while loop that calls Claude with MCP tools
- Tool Execution: Routes tool calls to appropriate backend MCP servers
- Code Execution: Runs TypeScript in isolated Docker containers
Benefits of Programmatic Tool Use
- Composition: Chain multiple tools without waiting between calls
- State: Store variables and reuse results
- Loops/Conditionals: Handle complex logic in code
- Error Handling: Try/catch and retry logic
- Efficiency: Make many tool calls in one execution
- Skills Library: Build reusable patterns over time
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.