codemesh

codemesh

CodeMesh enables AI agents to orchestrate any MCP server by writing TypeScript code, with self-improving capabilities through auto-augmentation of tool documentation.

Category
访问服务器

README

<div align="center"> <img src="./assets/codemesh-logo.svg" alt="CodeMesh Logo" width="200" /> <h1>CodeMesh</h1> <p><strong>Agents Write Code. Orchestrate Everything.</strong></p>

<p> <a href="https://www.npmjs.com/package/codemesh"><img src="https://img.shields.io/npm/v/codemesh?color=0ad7f9" alt="npm version" /></a> <a href="https://github.com/kiliman/codemesh/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=2dd4bf" alt="License" /></a> <a href="https://www.codemeshmcp.com"><img src="https://img.shields.io/badge/docs-codemeshmcp.com-34d399" alt="Documentation" /></a> </p>

<p><em>The world's first self-improving MCP server</em></p> </div>

📺 See It In Action

CodeMesh Demo

Watch: How Agent A explores and documents, then Agent B one-shots the same task - 2.6x faster!

📖 Read the story: Building CodeMesh - From Idea to Self-Improving Intelligence

What is CodeMesh?

CodeMesh lets AI agents write TypeScript code to orchestrate ANY MCP server. One prompt. One code block. Multiple servers working together.

Instead of exposing dozens of individual tools, CodeMesh provides just 3 tools:

  1. discover-tools - See what's available (context-efficient overview)
  2. get-tool-apis - Get TypeScript APIs for specific tools
  3. execute-code - Execute TypeScript that calls multiple tools

🎉 The Innovation: Auto-Augmentation

When agents encounter unclear tool outputs, CodeMesh forces documentation before proceeding. This creates compound intelligence - each exploration helps ALL future agents.

Proven: Agent A explored and documented. Agent B one-shot the same task. 2.6x faster! 🚀

Installation

1. Add CodeMesh to Claude Desktop

claude mcp add codemesh npx -y codemesh

Or manually add to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "codemesh": {
      "command": "npx",
      "args": ["-y", "codemesh"]
    }
  }
}

2. Create Configuration

Create a .codemesh/config.json file in your project directory to configure which MCP servers CodeMesh should connect to:

{
  "logging": {
    "enabled": true,
    "level": "info",
    "logDir": ".codemesh/logs"
  },
  "servers": [
    {
      "id": "filesystem",
      "name": "File System",
      "type": "stdio",
      "command": ["npx", "@modelcontextprotocol/server-filesystem", "/path/to/directory"],
      "timeout": 30000
    },
    {
      "id": "brave-search",
      "name": "Brave Search",
      "type": "stdio",
      "command": ["npx", "-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "${BRAVE_API_KEY}"
      }
    },
    {
      "id": "weather",
      "name": "Weather Server",
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  ]
}

Server Configuration Options

Each server entry supports:

  • id (required) - Unique identifier for the server
  • name (required) - Human-readable name
  • type (required) - Server type: "stdio", "http", or "websocket"
  • command (stdio only) - Command array to start the server
  • cwd (stdio only) - Working directory for the command
  • url (http/websocket only) - Server URL
  • env (optional) - Environment variables for the server
  • timeout (optional) - Connection timeout in milliseconds

Environment Variable Substitution

Use ${VAR} or ${VAR:-default} syntax in your config for secure credential management:

{
  "env": {
    "API_KEY": "${MY_API_KEY}",
    "ENDPOINT": "${API_ENDPOINT:-https://default.api.com}"
  }
}

This works with any environment variable manager (Doppler, 1Password, etc.) and keeps your config safe to commit.

Logging Configuration

Enable markdown-based file logging to track tool calls, code execution, and responses:

{
  "logging": {
    "enabled": true,
    "level": "info",
    "logDir": ".codemesh/logs"
  }
}

Options:

  • enabled (boolean) - Enable/disable file logging
  • level ("debug" | "info" | "warn" | "error") - Minimum log level to record
  • logDir (string) - Directory for log files (defaults to .codemesh/logs)

Log Format:

Logs are saved as markdown files (.codemesh/logs/YYYY-MM-DD.md) with syntax highlighting:

## 14:52:45 - execute-code

**Duration:** 2.1s
**Status:** ✅ Success

### Request

` ``typescript
const alerts = await weatherServer.getAlerts({ state: 'CA' })
return alerts ` ``

### Console Output

` ``
Found 3 alerts ` ``

### Response

` ``json
{ "count": 3, "alerts": [...] } ` ``

Perfect for debugging, demo preparation, and understanding what CodeMesh is doing! 🎯

How It Works

CodeMesh uses an intelligent three-step workflow that happens automatically when you give it a prompt:

Example: Real-World Usage

You ask Claude:

"Use CodeMesh to give me the top 3 weather alerts for Moyock, NC"

Behind the scenes, CodeMesh automatically:

  1. Discovers Tools (discover-tools)

    • Sees geocode tool (to convert "Moyock, NC" to coordinates)
    • Sees getAlerts tool from weather server
    • Context-efficient: only shows tool names and descriptions
  2. Loads APIs (get-tool-apis)

    • Requests TypeScript function signatures for geocode and getAlerts
    • Generates type-safe APIs: geocodeServer.geocode({ location }) and weatherServer.getAlerts({ state })
    • Includes any existing augmentation documentation from previous runs
  3. Writes & Executes Code (execute-code)

    • CodeMesh writes TypeScript code that:
      • Calls geocodeServer.geocode to get coordinates
      • Calls weatherServer.getAlerts with the state
      • Parses results and filters to top 3 by severity
    • Executes in secure VM2 sandbox (30s timeout)
    • Returns formatted results

Self-Improving Intelligence (Auto-Augmentation)

The Problem: Most MCP servers don't document their output formats. Is it JSON? Plain text? Key-value pairs? Arrays?

CodeMesh's Solution: When the agent struggles to parse output, it automatically:

  1. Enters EXPLORATION Mode

    • Adds // EXPLORING comment to the code
    • Calls the tool to examine actual output structure
    • Figures out: Is it JSON? What fields exist? What's the structure?
  2. Gets Blocked by Design

    • CodeMesh returns an ERROR (not success) for exploration mode
    • Forces the agent to document before proceeding
    • "You cannot parse until you create augmentation!"
  3. Creates Augmentation (add-augmentation)

    • Agent writes markdown documentation with:
      • Output format description
      • Field definitions
      • Example output (actual data from exploration)
      • Working parsing code (TypeScript examples)
    • Saves to .codemesh/[server-id].md
  4. Enhanced for Next Time

    • Next get-tool-apis call includes augmentation in JSDoc
    • Future agents see the parsing examples and data structure
    • One-shot success - no trial-and-error needed!

Result: Agent A struggles and documents. Agent B one-shots it. Agent C one-shots it. Compound intelligence!

Example: What CodeMesh Writes For You

Your prompt:

"Find the 3 most severe weather alerts in North Carolina"

CodeMesh automatically writes:

// Step 1: Fetch weather alerts
const alerts = await weatherServer.getAlerts({ state: 'NC' })
const alertsData = JSON.parse(alerts.content[0].text)

// Step 2: Define severity hierarchy
const severityHierarchy = ['Extreme', 'Severe', 'Moderate', 'Minor']
const highestSeverity = severityHierarchy.find((severity) =>
  alertsData.features.some((alert) => alert.properties.severity === severity),
)

// Step 3: Filter and return top 3
const topAlerts = alertsData.features.filter((alert) => alert.properties.severity === highestSeverity).slice(0, 3)

return {
  count: topAlerts.length,
  severity: highestSeverity,
  alerts: topAlerts,
}

You get intelligent results - no manual tool calls, no trial-and-error, just results!

Why CodeMesh?

❌ The Problem

  • Traditional MCP: Expose 50+ tools, flood agent context
  • Agents can't coordinate tools from different servers
  • Trial-and-error on unclear tool outputs wastes tokens
  • Every agent repeats the same mistakes

✨ The CodeMesh Way

  • Just 3 tools: discover, get APIs, execute code
  • Agents write TypeScript calling multiple servers at once
  • Auto-augmentation forces documentation of outputs
  • Knowledge compounds: Agent A helps Agent B

🏆 Key Features

  • 🧠 Self-Improving - Agents document unclear outputs, future agents benefit
  • 🔗 Multi-Server Orchestration - Coordinate tools from different MCP servers in single code block (HTTP + stdio + websocket)
  • 🎯 Context Efficient - Load only the tools you need, 3 tools vs 50+
  • 🚀 Zero Configuration - Point to your MCP servers and go, works with ANY compliant MCP server
  • Production Ready - Type-safe TypeScript execution in VM2 sandbox, authentication, error handling
  • 🔒 Secure by Default - Environment variable substitution, principle of least privilege

Best Practices

Use Subagents for Maximum Context Efficiency

While CodeMesh is context-efficient internally (tiered discovery prevents tool pollution), we strongly recommend spawning a subagent to execute CodeMesh operations. This keeps your main agent's context clean while CodeMesh does the heavy lifting.

Example with Claude Code:

User: "Analyze the weather data and file structure for my project"
Main Agent: Let me spawn a subagent to handle this task...

Main agent uses the Task tool to spawn a codemesh subagent with the prompt: "Use CodeMesh to analyze weather alerts for NC and correlate with local file timestamps"

Benefits:

  • 🧹 Main context stays clean
  • ⚡ Subagent can iterate on CodeMesh without polluting parent
  • 🎯 Specialized subagent focused solely on orchestration
  • 📦 Results summarized back to main agent when complete

When NOT to use subagents:

  • Simple single-tool calls (just use the tool directly)
  • When you need tight integration with main conversation flow

See examples/codemesh-agent.md for a ready-to-use Claude Code agent configuration.

Contributing

Want to contribute to CodeMesh development? See CONTRIBUTING.md for developer setup, architecture details, and development workflows.


<div align="center">

Built with Sonnet 4.5

From Claudia, with Love ❤️

Built with Claude Code using Sonnet 4.5 for the Anthropic MCP Hackathon

🌐 Website📖 Blog📦 NPM📺 Demo Video

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选