Skip to main content
Glama
QUICKSTART.mdβ€’6.07 kB
# Quick Start Guide - code2mcp Get up and running with Code Mode in 5 minutes! ## βœ… What You've Built A working **Code Mode MCP Server** that: - Converts MCP tools into TypeScript APIs - Executes LLM-generated code in a secure sandbox - Reduces token usage by up to 98% for complex workflows - Hides API keys from LLM-generated code ## πŸ“‹ Prerequisites - βœ… Node.js installed - βœ… Claude Code or Claude Desktop - βœ… At least one MCP server to connect to (optional for testing) ## πŸš€ Step 1: Test the Build ```bash cd /Users/blaser/Documents/Projects/code2mcp # Verify build succeeded ls -la build/index.js # Should show: -rwxr-xr-x ... build/index.js ``` ## πŸ”§ Step 2: Configure MCP Servers (Optional) For testing purposes, you can skip this and run with zero MCP servers. To add real servers: Edit `src/index.ts` around line 30: ```typescript const MCP_SERVERS: MCPServerConfig[] = [ { name: 'example-server', transport: 'stdio', command: 'node', args: ['/absolute/path/to/your-mcp-server/build/index.js'], env: { API_KEY: process.env.EXAMPLE_API_KEY || '', }, }, ]; ``` Then rebuild: ```bash npm run build ``` ## πŸ“ Step 3: Register with Claude Code Add to your `~/.claude.json`: ```json { "mcpServers": { "code2mcp": { "command": "node", "args": ["/Users/blaser/Documents/Projects/code2mcp/build/index.js"], "env": { "LOG_LEVEL": "info" } } } } ``` ## 🎯 Step 4: Test It! ### Test 1: Basic Sandbox Execution Start Claude Code and try: > "Use code2mcp to execute this code: `console.log('Hello from Code Mode!')`" **Expected Output:** ``` === Execution Logs === Hello from Code Mode! === Result === (undefined) Execution time: 45ms ``` ### Test 2: TypeScript Compilation > "Execute this TypeScript code: `const x: number = 42; console.log('Answer:', x);`" **Expected Output:** ``` === Execution Logs === Answer: 42 === Result === (undefined) Execution time: 52ms ``` ### Test 3: Multi-step Logic > "Execute code that creates an array, filters it, and logs the result" Claude might write: ```typescript const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const evens = numbers.filter(n => n % 2 === 0); console.log('Even numbers:', evens); console.log('Count:', evens.length); ``` ## πŸ”Œ Step 5: Connect Real MCP Servers Once you have MCP servers configured (Step 2), Claude can call them: **Example with a weather MCP server:** > "Get the weather for San Francisco" Claude writes: ```typescript const weather = await __mcp_call('weather__get_current', { city: 'San Francisco' }); console.log('Temperature:', weather.temperature, 'Β°F'); console.log('Conditions:', weather.conditions); ``` ## πŸŽ“ Understanding Code Mode ### Standard MCP (Token Heavy) ``` Claude Context: β”œβ”€ Tool 1 definition (500 tokens) β”œβ”€ Tool 2 definition (500 tokens) β”œβ”€ ...50 tools... (25,000 tokens) β”œβ”€ Intermediate result 1 (10,000 tokens) β”œβ”€ Intermediate result 2 (10,000 tokens) └─ Total: ~45,000+ tokens ``` ### Code Mode (Token Light) ``` Claude Context: β”œβ”€ execute_code tool (500 tokens) β”œβ”€ Code Claude writes (2,000 tokens) β”œβ”€ Final logs only (500 tokens) └─ Total: ~3,000 tokens Intermediate data stays in sandbox! ⚑ ``` ## πŸ›  Development Workflow ### Watch Mode (Hot Reload) ```bash npm run dev ``` ### Build for Production ```bash npm run build ``` ### Test with MCP Inspector ```bash npm run inspector ``` ### View Logs Logs go to stderr. When running via Claude Code, check terminal output: ```bash # Run Claude Code from terminal to see logs claude ``` ## πŸ“Š Verify Installation Check that everything is working: ```bash # 1. Build exists ls -la build/index.js # 2. Dependencies installed npm list --depth=0 # 3. TypeScript compiles npm run build # 4. No vulnerabilities npm audit ``` All green? You're ready! βœ… ## πŸ› Troubleshooting ### Build Fails ```bash # Clean and rebuild rm -rf build node_modules npm install npm run build ``` ### Claude Code Doesn't See the Tool 1. Check `~/.claude.json` has correct path 2. Restart Claude Code 3. Verify build/index.js exists and is executable ### Execution Errors - Check logs in terminal where Claude Code is running - Verify `LOG_LEVEL=debug` in .claude.json for verbose output ### No MCP Servers Connected - This is OK for testing! The server works with zero MCP servers - You can test sandbox execution without any external servers ## πŸ“š Next Steps 1. **Read the docs**: `DOCS/Etc/CODE_MODE_IMPLEMENTATION_PLAN.md` 2. **Connect MCP servers**: Add your existing MCP servers 3. **Explore examples**: Try complex multi-tool workflows 4. **Improve security**: Consider Deno or isolated-vm for production ## πŸŽ‰ Success Criteria You'll know it's working when: - βœ… Build completes without errors - βœ… Claude Code sees the `execute_code` tool - βœ… Simple console.log() executes and returns logs - βœ… TypeScript code compiles and runs - βœ… (Optional) MCP tools can be called via `__mcp_call()` ## πŸ’‘ Example Use Cases Once you have MCP servers connected: ### Multi-Step Workflow ```typescript // Fetch document from Google Drive (50KB document) const doc = await __mcp_call('google_drive__get_document', { documentId: 'abc123' }); // Analyze it (stays in sandbox!) const wordCount = doc.content.split(' ').length; console.log('Word count:', wordCount); // Update Salesforce (document never enters Claude's context!) await __mcp_call('salesforce__update', { id: 'lead-xyz', notes: `Document analyzed: ${wordCount} words` }); ``` **Token savings: 98%!** The 50KB document never enters Claude's context. ## πŸ”— Resources - [Cloudflare Code Mode Blog](https://blog.cloudflare.com/code-mode/) - [MCP Documentation](https://modelcontextprotocol.io/) - [Project Documentation](DOCS/) --- **Congratulations!** You've successfully implemented Code Mode! 🎊 This is a **revolutionary approach** to using MCP that will transform how AI agents interact with tools. Ready to save 98% of your tokens? Start coding! πŸš€

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blas0/code2mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server