Skip to main content
Glama

克劳德代码 MCP

Claude Code MCP 是Claude Code作为模型上下文协议 (MCP)服务器的实现。该项目允许您通过标准化的 MCP 接口使用 Claude Code 强大的软件工程功能。

⚠️ 免责声明 ⚠️

Claude Code MCP 是由 DevinAI 自动生成的项目,DevinAI 受提示分析 Claude Code 代码库,并生成 MCP 服务器。

这是一个概念证明,我不建议任何人使用。

什么是克劳德密码?

Claude Code 是 Anthropic 开发的用于软件工程任务的 CLI 工具,由 Claude 提供支持。它提供了一系列工具和功能,可帮助开发人员完成以下工作:

  • 代码生成和编辑

  • 代码审查和分析

  • 调试和故障排除

  • 文件系统操作

  • Shell命令执行

  • 项目探索与理解

原始实现可作为 JavaScript 模块使用,该模块定义了与 Claude 的 API 交互的提示和工具。

Related MCP server: Gemini MCP

什么是 MCP?

模型上下文协议 (MCP) 是 AI 模型的标准化接口,可实现不同模型和提供商之间一致的交互模式。MCP 定义:

  • 工具:模型可以调用来执行操作的函数

  • 资源:模型可以访问的外部数据

  • 提示:预定义对话模板

通过将 Claude Code 实现为 MCP 服务器,我们使其功能可供任何兼容 MCP 的客户端使用,从而实现更高的互操作性和灵活性。

特征

  • 作为 MCP 服务器全面实现 Claude Code 功能

  • 提供文件操作、shell 命令和代码分析的工具

  • 公开用于访问文件系统和环境信息的资源

  • 包括一般 CLI 交互和代码审查的提示

  • 与任何 MCP 客户端兼容

  • 具有完全类型安全性的 TypeScript 实现

安装

# Clone the repository
git clone https://github.com/auchenberg/claude-code-mcp.git
cd claude-code-mcp

# Install dependencies
npm install

# Build the project
npm run build

用法

作为独立服务器运行

# Start the server
npm start

与 MCP 客户端一起使用

Claude Code MCP 可与任何 MCP 客户端配合使用。以下是使用 MCP TypeScript SDK 连接的示例:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const transport = new StdioClientTransport({
  command: "node",
  args: ["dist/index.js"]
});

const client = new Client(
  {
    name: "example-client",
    version: "1.0.0"
  },
  {
    capabilities: {
      prompts: {},
      resources: {},
      tools: {}
    }
  }
);

await client.connect(transport);

// Use Claude Code through MCP
const result = await client.callTool({
  name: "bash",
  arguments: {
    command: "ls -la"
  }
});

console.log(result);

可用工具

Claude Code MCP 提供以下工具:

  • bash :执行带有安全限制和超时选项的 shell 命令

  • readFile :从文件系统读取文件,带有行偏移和限制选项

  • listFiles :列出文件和目录以及详细的元数据

  • searchGlob :搜索与 glob 模式匹配的文件

  • grep :使用正则表达式模式支持在文件中搜索文本

  • think :用于思考复杂问题的无操作工具

  • codeReview :分析和审查代码中的错误、安全问题和最佳实践

  • editFile :创建或编辑具有指定内容的文件

工具详细信息

狂欢

{
  command: string;  // The shell command to execute
  timeout?: number; // Optional timeout in milliseconds (max 600000)
}

bash 工具包含安全限制,可防止执行潜在危险的命令,如curlwget等。

读文件

{
  file_path: string; // The absolute path to the file to read
  offset?: number;   // The line number to start reading from
  limit?: number;    // The number of lines to read
}

搜索全局

{
  pattern: string;  // The glob pattern to match files against
  path?: string;    // The directory to search in (defaults to current working directory)
}

grep

{
  pattern: string;   // The regular expression pattern to search for
  path?: string;     // The directory to search in (defaults to current working directory)
  include?: string;  // File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")
}

可用资源

  • file :访问文件内容( file://{path}

    • 提供对文件内容的直接访问,并进行适当的错误处理

    • 返回指定文件的全文内容

  • 目录:列出目录内容( dir://{path}

    • 返回文件信息对象的 JSON 数组

    • 每个对象包括名称、路径、isDirectory、大小和修改日期

  • environment :获取系统环境信息( env://info

    • 返回有关系统环境的信息

    • 包括 Node.js 版本、npm 版本、操作系统信息和环境变量

可用提示

  • generalCLI :Claude 代码的通用 CLI 提示符

    • 为 Claude 提供全面的系统提示,使其充当 CLI 工具

    • 包括语气、风格、主动性和遵循惯例的指导

    • 自动包含环境详细信息

  • codeReview :提示审查代码

    • 代码审查任务的专门提示

    • 分析代码中的错误、安全漏洞、性能问题和最佳实践

  • prReview :提示审查拉取请求

    • PR 审核任务的专门提示

    • 分析 PR 变化并提供全面的反馈

  • initCodebase :使用代码库文档初始化一个新的 CLAUDE.md 文件

    • 为 build/lint/test 命令和代码风格指南创建文档

    • 有助于使用 Claude Code 创建新项目

发展

# Run in development mode with auto-reload
npm run dev

建筑学

Claude Code MCP 采用模块化架构构建:

claude-code-mcp/
├── src/
│   ├── server/
│   │   ├── claude-code-server.ts  # Main server setup
│   │   ├── tools.ts               # Tool implementations
│   │   ├── prompts.ts             # Prompt definitions
│   │   └── resources.ts           # Resource implementations
│   ├── utils/
│   │   ├── bash.ts                # Shell command utilities
│   │   └── file.ts                # File system utilities
│   └── index.ts                   # Entry point
├── package.json
├── tsconfig.json
└── README.md

实施遵循以下关键原则:

  1. 模块化:每个组件(工具、提示、资源)都在单独的模块中实现

  2. 类型安全:所有组件的完整 TypeScript 类型定义

  3. 错误处理:针对所有操作的全面错误处理

  4. 安全:针对潜在危险操作的安全限制

实现细节

MCP 服务器设置

主服务器在claude-code-server.ts中设置:

export async function setupClaudeCodeServer(server: McpServer): Promise<void> {
  // Set up Claude Code tools
  setupTools(server);
  
  // Set up Claude Code prompts
  setupPrompts(server);
  
  // Set up Claude Code resources
  setupResources(server);
}

工具实现

工具是使用 MCP SDK 的工具注册方法实现的:

server.tool(
  "toolName",
  "Tool description",
  {
    // Zod schema for tool arguments
    param1: z.string().describe("Parameter description"),
    param2: z.number().optional().describe("Optional parameter description")
  },
  async ({ param1, param2 }) => {
    // Tool implementation
    return {
      content: [{ type: "text", text: "Result" }]
    };
  }
);

资源实施

资源使用MCP SDK的资源注册方法实现:

server.resource(
  "resourceName",
  new ResourceTemplate("resource://{variable}", { list: undefined }),
  async (uri, variables) => {
    // Resource implementation
    return {
      contents: [{
        uri: uri.href,
        text: "Resource content"
      }]
    };
  }
);

执照

麻省理工学院

致谢

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

免责声明

该项目与 Anthropic 无正式关联。Claude Code 是 Anthropic 的产品,而本项目是 Claude Code 作为 MCP 服务器的独立实现。

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Latest Blog Posts

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/auchenberg/claude-code-mcp'

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