CodeMesh is a "Code Mode" MCP server that executes TypeScript code against multiple MCP tools. Think of it as a universal adapter that lets agents write code to orchestrate ANY MCP server.
Instead of exposing individual MCP tools, CodeMesh provides:
discover-tools- See what's available (context-efficient overview)get-tool-apis- Get TypeScript APIs for specific toolsexecute-code- Execute TypeScript that calls multiple toolsadd-augmentation- Document unclear outputs (self-improving!)
packages/
├── codemesh-server/ # Main CodeMesh MCP server
├── client/ # CLI for testing
├── example-server/ # Demo HTTP server
├── weather-server/ # Demo stdio server
└── geocode-server/ # Demo stdio server
- ✅ HTTP, stdio, and websocket transports
- ✅ Connect to multiple servers simultaneously
- ✅ Execute code that calls tools from different servers
- ✅ Works with any MCP-compliant server
- ✅ Tiered discovery prevents context pollution
- ✅ Load only the tool APIs you need
- ✅ Single execute-code tool vs dozens of individual tools
- ✅ Auto-augmentation: Agents document unclear outputs
- ✅
// EXPLORINGcomment: Triggers mandatory documentation workflow - ✅ Nuclear option: Returns ERROR until augmentation created
- ✅ Proven effective: Agent B one-shotted what Agent A struggled with!
- ✅ Knowledge compounds: Each exploration helps future agents
- ✅ MCP SDK compliant env var handling
- ✅ Environment variable substitution:
${VAR:-default} - ✅ Principle of least privilege
- ✅ Safe to commit configs (use env vars for secrets)
The Problem: Agents trial-and-error unclear tool outputs instead of documenting them.
The Solution: Make exploration without documentation an ERROR!
-
Agent explores with
// EXPLORINGcomment:// EXPLORING: checking output format const result = await filesystemServer.getFileInfo({ path: 'test.txt' }) console.log(result)
-
CodeMesh returns ERROR with output + mandatory instructions
-
Agent creates augmentation using
add-augmentation:- Output format description
- Field documentation
- Example output
- Parsing code
-
Future agents benefit via enhanced JSDoc in
get-tool-apis
- Agent A: Used
// EXPLORING, forced to create 2 augmentations - Agent B: Same task, one-shot success using A's docs
- Result: PROVEN self-improving system! 🎉
# Build
pnpm build
# Run codemesh server (stdio)
npx tsx packages/codemesh-server/src/index.ts
# Test with client
npx tsx packages/client/index.ts --stdio npx tsx packages/codemesh-server/src/index.ts --call-tool discover-tools.codemesh/config.json- MCP server configuration.codemesh/*.md- Tool augmentation docs (self-improving!)packages/codemesh-server/src/index.ts- Main toolspackages/codemesh-server/src/codeExecutor.ts- Code execution + exploration detectionpackages/codemesh-server/src/typeGenerator.ts- TypeScript type generationpackages/codemesh-server/src/config.ts- Configuration with env var substitution
// 1. Discover available tools
discover - tools()
// 2. Get TypeScript APIs for specific tools
get -
tool -
apis({
toolNames: ['filesystemServer.directoryTree', 'filesystemServer.getFileInfo'],
})
// 3. Execute TypeScript code
execute -
code({
code: `
const tree = await filesystemServer.directoryTree({ path: "/project" });
const files = JSON.parse(tree.content[0].text);
return files.length;
`,
})- Context Efficient: Load only what you need vs flooding context with all tools
- Multi-Server: Coordinate tools from different MCP servers in single code block
- Self-Improving: Agents document unclear outputs, helping all future agents
- Battle-Tested: Fresh Claude sessions one-shot tasks using augmentations
- Production Ready: Authentication, security, error handling all complete
CodeMesh was built for the Anthropic MCP Hackathon. Key innovations:
- Novel approach: "Code Mode" pattern for MCP (inspired by Cloudflare)
- Self-improving: Auto-augmentation via forced documentation (no one else has this!)
- Validated: Agent A documents → Agent B succeeds (proven compound intelligence)
- Production ready: Multi-server, auth, security all working
Title: "From Claudia, with Love ❤️" - Built with help from Claude Code using Sonnet 4.5
- Config location:
.codemesh/config.json(notmcp-config.json) - Augmentation files:
.codemesh/{serverId}.md - Exploration trigger:
// EXPLORINGcomment in code - Nuclear option: Returns ERROR to force augmentation (this is intentional!)
- Testing: Use
npx tsx packages/client/index.ts --stdio npx tsx packages/codemesh-server/src/index.ts - Best practice: Recommend spawning a subagent (Task tool) for CodeMesh operations to keep main context clean
- Example: "Let me spawn a codemesh subagent to handle this multi-tool orchestration task"
- See
examples/codemesh-agent.mdfor ready-to-use agent configuration