Thank you for your interest in contributing to CodeMesh! This guide covers everything you need to know to develop and test CodeMesh.
packages/
├── codemesh-server/ # Main CodeMesh MCP server
│ ├── src/
│ │ ├── index.ts # Server entry point, tool definitions
│ │ ├── config.ts # Configuration loader with env var substitution
│ │ ├── toolDiscovery.ts # Multi-server tool discovery
│ │ ├── typeGenerator.ts # JSON Schema → TypeScript conversion
│ │ ├── runtimeWrapper.ts # Tool execution wrapper
│ │ └── codeExecutor.ts # VM2 sandbox for TypeScript execution
│ └── package.json
├── client/ # CLI client for testing
├── example-server/ # Demo HTTP MCP server
├── weather-server/ # Demo stdio weather MCP server
└── geocode-server/ # Demo stdio geocoding MCP server
.codemesh/ # Local configuration
├── config.json # MCP server configuration
└── *.md # Auto-generated augmentations
-
Configuration System (
config.ts)- Loads
.codemesh/config.json - Supports stdio, HTTP, and websocket server types
- Environment variable substitution with
${VAR}syntax - Follows MCP SDK security practices
- Loads
-
Tool Discovery (
toolDiscovery.ts)- Connects to multiple MCP servers simultaneously
- Extracts tool schemas, descriptions, metadata
- Supports all three transport types (stdio, HTTP, websocket)
- Proper connection lifecycle management
-
Type Generation (
typeGenerator.ts)- Converts JSON schemas to TypeScript interfaces using
json-schema-to-typescript - Generates type-safe function signatures
- Creates comprehensive tool metadata for runtime
- Converts JSON schemas to TypeScript interfaces using
-
Runtime Wrapper (
runtimeWrapper.ts)- Creates executable TypeScript functions from tool metadata
- Proxies function calls to actual MCP tools
- Manages connections across multiple servers
- Safe function naming (
toolName_serverIdpattern)
-
Code Executor (
codeExecutor.ts)- Sandboxed TypeScript execution using VM2
- Compiles TypeScript to JavaScript
- Injects tool functions into execution context
- 30-second timeout, error handling
- Exploration mode detection for auto-augmentation
Step 1: discover-tools - Returns high-level overview of available tools from all configured servers. Context-efficient.
Step 2: get-tool-apis - Generates and returns TypeScript function signatures for specific tools. Only loads what's needed.
Step 3: execute-code - Executes TypeScript code with injected tool functions in VM2 sandbox.
When code includes // EXPLORING comments, the executor:
- Detects the exploration pattern
- Returns results as an ERROR (nuclear option approach)
- Forces agent to create augmentation documentation
- Agent calls
add-augmentationtool to save markdown to.codemesh/[server-id].md - Future
get-tool-apiscalls include enhanced JSDoc from augmentations
Result: Self-improving system where agents document unclear outputs for future benefit.
- Node.js 18+
- pnpm (recommended) or npm
# Clone the repository
git clone https://github.com/kiliman/codemesh.git
cd codemesh
# Install dependencies
pnpm install
# Build all packages
pnpm build# Start example HTTP server (for testing multi-server support)
pnpm dev:example-server
# Start CodeMesh server in watch mode
pnpm dev:codemesh-server:watch
# Build all packages
pnpm buildThe packages/client provides a generic CLI for testing any MCP server:
# Discover tools from CodeMesh
npx tsx packages/client/index.ts \
--stdio tsx packages/codemesh-server/src/index.ts \
--list-tools
# Call discover-tools
npx tsx packages/client/index.ts \
--stdio tsx packages/codemesh-server/src/index.ts \
--call-tool discover-tools
# Call get-tool-apis
npx tsx packages/client/index.ts \
--stdio tsx packages/codemesh-server/src/index.ts \
--call-tool get-tool-apis \
--tool-args-file tmp/tool-args.json
# Call execute-code
npx tsx packages/client/index.ts \
--stdio tsx packages/codemesh-server/src/index.ts \
--call-tool execute-code \
--code-file tmp/test.ts \
--tool-args-file tmp/execute-args.json# Make sure example-server is running first
pnpm dev:example-server
# Then test with client
npx tsx packages/client/index.ts \
--connect http://localhost:3000/mcp \
--list-tools# Start interactive session with CodeMesh
npx tsx packages/client/index.ts \
--stdio tsx packages/codemesh-server/src/index.ts \
--interactive
# Or with HTTP server
npx tsx packages/client/index.ts \
--connect http://localhost:3000/mcp \
--interactiveThe .codemesh/config.json file defines which MCP servers CodeMesh connects to:
{
"servers": [
{
"id": "example-http",
"name": "Example HTTP Server",
"type": "http",
"url": "http://localhost:3000/mcp"
},
{
"id": "example-stdio",
"name": "Example Stdio Server",
"type": "stdio",
"command": ["node", "dist/index.js"],
"cwd": "./packages/example-server",
"env": {
"NODE_ENV": "development"
}
},
{
"id": "example-websocket",
"name": "Example WebSocket Server",
"type": "websocket",
"url": "ws://localhost:3001/mcp"
}
]
}Supports ${VAR} and ${VAR:-default} syntax:
{
"servers": [
{
"id": "brave-search",
"name": "Brave Search",
"type": "stdio",
"command": ["npx", "-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "${BRAVE_API_KEY}"
}
}
]
}Use config.example.json for version control with placeholders.
Tools are exposed as serverId.toolName (camelCase) to avoid collisions:
// Multiple servers can have a 'search' tool
await braveSearch.search({ query: 'test' })
await googleSearch.search({ query: 'test' })- 30-second execution timeout
- No
eval()orwasmaccess - Limited sandbox with only necessary globals
- Console output capture for debugging
Code can call tools from multiple servers in a single execution:
// HTTP server
const greeting = await exampleServer.greet({ name: 'Developer' })
// Stdio server 1
const alerts = await weatherServer.getAlerts({ state: 'NC' })
// Stdio server 2
const files = await filesystemServer.listDirectory({ path: '/tmp' })
// Process results together
return { greeting, alertCount: alerts.length, fileCount: files.length }To test the auto-augmentation workflow:
- Configure a server with unclear output format
- Execute code with
// EXPLORINGcomment - Verify error is returned forcing augmentation
- Call
add-augmentationtool with documentation - Call
get-tool-apisagain to see enhanced JSDoc - Execute code without
// EXPLORINGto verify success
- Use
console.log()in executed code for debugging - Check
.codemesh/*.mdfiles to see augmentations - Run servers in separate terminals to see their logs
- Use
--tool-args-filewith CLI to avoid bash escaping issues
- TypeScript with strict mode
- ESM modules (
.jsextensions in imports required) - Zod for schema validation
- Conventional commits for git messages
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes with conventional commits
- Run tests:
pnpm test - Push to your fork:
git push origin feature/amazing-feature - Open a Pull Request
Open an issue on GitHub or reach out to the maintainers!
Built with love by Michael and Claudia 💙