🚀 Code Mode MCP Server
This project offers a local implementation of the "Code Mode" workflow for MCP servers. Instead of dealing with multiple tool calls, LLMs can write TypeScript/JavaScript code to access MCP servers via a simple HTTP proxy.
🚀 Quick Start
This repo has been deprecated. I've shifted my focus to a more refined approach: https://github.com/jx-codes/lootbox.
✨ Features
- LLM-Friendly: Leverages LLMs' strength in writing code rather than complex tool calling.
- Simple Workflow: Uses a single tool
execute_code for LLMs to interact with MCP servers.
- Flexible Configuration: Allows customization through
codemode-config.json and .mcp.json files.
- Security: Runs code in a Deno sandbox with restricted access and timeout settings.
📦 Installation
Prerequisites
- Bun (latest version)
- Deno (for code execution sandbox)
- An MCP-compatible client (Claude Desktop, Cursor, VS Code with Copilot, etc.)
Setup
- Clone the repository
git clone https://github.com/jx-codes/codemode-mcp.git
cd codemode-mcp
- Install dependencies
bun install
- Configure the server (optional)
Create a
codemode-config.json file to customize settings:
{
"proxyPort": 3001,
"configDirectories": [
"~/.config/mcp/servers",
"./mcp-servers",
"./"
]
}
- Set up your MCP servers
Create a
.mcp.json file with your MCP server configurations in any of the directories you specified above:
{
"mcpServers": {
"fs": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
"env": {}
}
}
}
💻 Usage Examples
Basic Usage
const servers = await fetch("http://localhost:3001/mcp/servers").then((r) =>
r.json()
);
console.log("Available servers:", servers);
const result = await fetch("http://localhost:3001/mcp/call", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
server: "fs",
tool: "read_file",
args: { path: "/tmp/example.txt" },
}),
}).then((r) => r.json());
console.log("File contents:", result);
Advanced Usage
const files = await fetch("http://localhost:3001/mcp/call", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
server: "fs",
tool: "list_directory",
args: { path: "/tmp" },
}),
}).then((r) => r.json());
for (const file of files.content[0].text.split("\n")) {
if (file.endsWith(".txt")) {
const content = await fetch("http://localhost:3001/mcp/call", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
server: "fs",
tool: "read_file",
args: { path: `/tmp/${file}` },
}),
}).then((r) => r.json());
console.log(`${file}: ${content.content[0].text.length} characters`);
}
}
📚 Documentation
Tools
execute_code
Executes TypeScript/JavaScript code with network access to the MCP proxy.
Parameters:
code (string): Code to execute
typescript (boolean): TypeScript mode (default: true)
Proxy Endpoints:
GET /mcp/servers - List available MCP servers
GET /mcp/{server}/tools - List tools for server
POST /mcp/call - Call tool (body: {server, tool, args})
check_deno_version
Check Deno installation status.
list_servers_with_tools
Get a comprehensive overview of all available MCP servers and their tools. Returns structured JSON data optimized for LLM consumption, containing complete tool schemas and server status information.
JSON Output Structure:
{
"summary": {
"totalServers": 2,
"successfulServers": 2,
"totalTools": 4
},
"servers": [
{
"server": "filesystem",
"status": "success",
"toolCount": 3,
"tools": [
{
"name": "read_file",
"description": "Read contents of a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "File path to read"
}
},
"required": ["path"]
}
}
]
},
{
"server": "database",
"status": "success",
"toolCount": 1,
"tools": [
{
"name": "query",
"description": "Execute a SQL query",
"inputSchema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "SQL query to execute"
}
},
"required": ["query"]
}
}
]
}
]
}
Configuration
Create codemode-config.json:
{
"proxyPort": 3001,
"configDirectories": ["~/.config/mcp/servers", "./mcp-servers", "./"]
}
Add your MCP servers to .mcp.json files in those directories:
{
"mcpServers": {
"fs": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
"env": {}
}
}
}
Why (Might) Work Better
| Approach |
Traditional MCP |
Code Mode |
| LLM Interaction |
LLMs struggle with tool syntax |
LLMs excel at writing code |
| Operation Chaining |
Hard to chain operations |
Code can chain operations naturally |
| Result Flow |
Each call goes through the neural network |
Results flow through code logic |
| Training Limitation |
Limited by training on synthetic tool examples |
Trained on millions of real code examples |
Security
- Code runs in Deno sandbox with network access only.
- No filesystem, environment, or system access.
- 30-second execution timeout.
- MCP servers accessed through controlled proxy.
- Temporary files auto-cleanup.
Troubleshooting
| Issue |
Solution |
| "Deno not installed" |
Install Deno and restart |
| "Permission denied" |
Code trying to access restricted resources |
| "Module not found" |
Use https:// URLs for imports |
| "Execution timeout" |
Optimize code or break into smaller operations |
TODO (Maybe)
- Provide a simpler API layer for the MCP proxy something like mcp.tool('name', args);
- Could easily be done by injecting our own typescript file into the Deno scope before running user code
- More config options
- Filter out the tools somehow
- Test it out more in my workflows and see the results
Code Source
Deno code remixed from: https://github.com/Timtech4u/deno-mcp-server