Token导航 LogoToken导航TokenDH.com
Opensrc MCP logo
开发工具stdio官方级别未说明来源级核验

Opensrc MCP

MCP Server

opensrc-mcp

一个采用codemode模式的MCP服务器,用于查询和获取依赖源代码,优化LLM处理效率。

工具数

1

提示词数

0

GitHub Stars

36

资源数

0
代码分析TypeScript开发工具依赖管理

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dmmulroy

提供方

dmmulroy

最后核验

2026/5/17 20:22

运行时

Node.js

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

npx opensrc-mcp

详细介绍

opensrc-mcp

用于获取和查询依赖源代码的代码模式MCP服务器。

为什么?

传统的MCP将工具直接暴露给LLM。此服务器使用 编码模式:代理编写执行服务器端的JavaScript,只返回结果。优点:

  • 上下文高效 -大型源代码树保持服务器端
  • 批量操作 -一次调用搜索/读取多个文件
  • LLM更擅长代码 -JS的训练数据比工具调用更多

安装

npm install -g opensrc-mcp
# or
npx opensrc-mcp

OpenCode配置

添加到您的OpenCode配置(~/.config/opencode/config.json 或项目 opencode.json):

{
  "mcp": {
    "opensrc": {
      "type": "local",
      "command": "npx",
      "args": ["-y", "opensrc-mcp"]
    }
  }
}

工具

execute

单个工具显示所有操作。代理编写运行服务器端的JS;只返回结果。

// Available in sandbox:
declare const opensrc: {
  // Read operations
  list(): Source[];
  has(name: string, version?: string): boolean;
  get(name: string): Source | undefined;
  files(sourceName: string, glob?: string): Promise;
  tree(sourceName: string, options?: { depth?: number }): Promise;
  grep(pattern: string, options?: {
    sources?: string[];
    include?: string;
    maxResults?: number;
  }): Promise;
  astGrep(sourceName: string, pattern: string, options?: {
    glob?: string;
    lang?: string | string[];
    limit?: number;
  }): Promise;
  read(sourceName: string, filePath: string): Promise;
  readMany(sourceName: string, paths: string[]): Promise>;
  resolve(spec: string): Promise
;

  // Mutation operations
  fetch(specs: string | string[], options?: { modify?: boolean }): Promise;
  remove(names: string[]): Promise;
  clean(options?: {
    packages?: boolean;
    repos?: boolean;
    npm?: boolean;
    pypi?: boolean;
    crates?: boolean;
  }): Promise;
};

declare const sources: Source[];  // All fetched sources
declare const cwd: string;        // Project directory

示例:

// List all fetched sources
async () => opensrc.list()

// Fetch npm package (auto-detects version from lockfile)
async () => opensrc.fetch("zod")

// Fetch multiple packages
async () => opensrc.fetch(["zod", "drizzle-orm", "hono"])

// Fetch GitHub repo at specific ref
async () => opensrc.fetch("vercel/ai@v3.0.0")

// Fetch from other registries
async () => opensrc.fetch("pypi:requests")
async () => opensrc.fetch("crates:serde")

// Get directory tree
async () => opensrc.tree("zod", { depth: 2 })

// Find TypeScript files
async () => opensrc.files("zod", "**/*.ts")

// Text search
async () => opensrc.grep("parse", { sources: ["zod"], include: "*.ts" })

// AST search (structural pattern matching)
async () => opensrc.astGrep("zod", "function $NAME($$$ARGS)", { glob: "**/*.ts" })

// Read a specific file
async () => opensrc.read("zod", "src/index.ts")

// Read multiple files (supports globs)
async () => opensrc.readMany("zod", ["src/index.ts", "packages/*/package.json"])

// Remove a source
async () => opensrc.remove(["zod"])

// Clean all npm packages
async () => opensrc.clean({ npm: true })

包格式

格式示例说明
``zodnpm(自动检测版本)
@zod@3.22.0npm特定版本
npm:npm:react显式npm
pypi:pypi:requestsPython/PyPI
pip:pip:flaskpypi的别名
crates:crates:serde锈迹/裂纹
cargo:cargo:tokio板条箱别名
owner/repovercel/aiGitHub仓库
owner/repo@refvercel/ai@v1.0.0GitHub at ref
github:owner/repogithub:facebook/react明确的GitHub

存储

来源存储在全球 ~/.local/share/opensrc/ (XDG兼容):

~/.local/share/opensrc/
├── sources.json           # Index of fetched sources
├── packages/              # npm/pypi/crates packages
│   └── zod/
│       ├── src/
│       ├── package.json
│       └── ...
└── repos/                 # GitHub repos
    └── github.com/
        └── vercel/
            └── ai/

覆盖 $OPENSRC_DIR$XDG_DATA_HOME.

运作原理

  1. 客服电话 execute JS代码工具: async () => opensrc.fetch("zod")
  2. 代码在沙盒中运行 vm 注入上下文 opensrc API
  3. 服务器通过以下方式获取包 opensrc (处理注册表查找、git克隆)
  4. 只有结果返回到代理上下文
┌─────────────────────────────────────────────────────────────┐
│                      Agent Context                          │
├─────────────────────────────────────────────────────────────┤
│  Tool call: execute({ code: "async () => opensrc.fetch..." })│
│                           ↓                                 │
│  Result: { success: true, source: { name: "zod", ... } }    │
└─────────────────────────────────────────────────────────────┘
                            ↕
┌─────────────────────────────────────────────────────────────┐
│                    opensrc-mcp Server                       │
├─────────────────────────────────────────────────────────────┤
│  Sandbox executes code with injected opensrc API            │
│  Full source tree stays here, never sent to agent           │
└─────────────────────────────────────────────────────────────┘

许可证

麻省理工学院

目录标签

目录标签

代码分析TypeScript开发工具依赖管理源代码查询本地部署LLM优化

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Node.js

来源包(packageName,安装包名)

opensrc-mcp

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP