TypeScript Definition Finder

Integrations

  • Locates original definitions of TypeScript symbols in codebases, including imported symbols from external packages, returning both definition locations and code snippets

TypeScript 定义查找器 MCP 服务器

模型上下文协议 (MCP) 服务器可帮助 AI 代码编辑器在您的代码库中查找 TypeScript 符号定义。当您需要在 TypeScript 项目中查找导入的符号、类、接口或函数的原始定义时,此工具尤其有用。

特征

  • 查找 TypeScript 符号的原始定义
  • 使用从外部包导入的符号
  • 返回定义位置和代码片段
  • 支持 stdio 接口,可与 AI 代码编辑器无缝集成

先决条件

  • Bun v1.2.2 或更高版本
  • 用于运行已编译服务器的 Node.js

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 TypeScript Definition Finder:

npx -y @smithery/cli install @runninghare/ts-def-mcp --client claude

手动安装

  1. 安装依赖项:
bun install
  1. 构建项目:
bun run build

用法

启动 stdio 服务器:

node dist/run.js

工具描述

服务器提供了find_typescript_definition工具,具有以下功能:

  • 工具名称find_typescript_definition
  • 触发命令/ts-def (如果您想强制 AI 编辑器找到引用的符号定义,则在Cursor中很有用)
  • 目的:在代码库中定位 TypeScript 符号的原始定义

输入参数

该工具需要三个参数:

  1. file_path (字符串):
    • 当前 TypeScript 文件的绝对路径
    • 例如: /path/to/your/project/src/index.ts
  2. line_content (字符串):
    • 包含要查找其定义的符号的整行
    • 用于定位文件中的正确行
    • 必须与文件中出现的行完全匹配
  3. column_number (数字):
    • 符号起始的列号(以 1 为基数)
    • 必须是符号第一个字符的准确列位置

示例

  1. 查找导入的符号定义

鉴于此导入声明:

import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

要找到从第 10 列开始的StdioServerTransport的定义,您可以使用:

{ "file_path": "~/my-mcp-project/src/index.ts", "line_content": "import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";", "column_number": 10 }

该工具的输出将是:

[ { "file": "~/my-mcp-project/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts", "type": "Definition", "location": "Line 9, Column 22", "codeSnippet": " 8 */\n 9 > export declare class StdioServerTransport implements Transport {\n 10 + private _stdin;\n 11 + private _stdout;\n 12 + private _readBuffer;\n 13 + private _started;\n 14 + constructor(_stdin?: Readable, _stdout?: Writable);\n 15 + onclose?: () => void;\n 16 + onerror?: (error: Error) => void;\n 17 + onmessage?: (message: JSONRPCMessage) => void;\n 18 + _ondata: (chunk: Buffer) => void;\n 19 + _onerror: (error: Error) => void;\n 20 + /**\n 21 + * Starts listening for messages on stdin.\n 22 + */\n 23 + start(): Promise<void>;\n 24 + private processReadBuffer;\n 25 + close(): Promise<void>;\n 26 + send(message: JSONRPCMessage): Promise<void>;\n 27 }\n" } ]
  1. 查找本地符号定义

对于本地类用法:

class MyService { private transport: StdioServerTransport; }

要查找从第 20 列开始的StdioServerTransport的定义,请使用:

{ "file_path": "/path/to/project/src/service.ts", "line_content": " private transport: StdioServerTransport;", "column_number": 20 }

响应格式

该工具返回一个 JSON 响应,其中包含:

  • 找到定义的文件路径
  • 定义的行号
  • 定义的实际代码片段

Claude 桌面示例

发展

该项目是使用 bun v1.2.2 中的bun init创建的。Bun 是一个快速的一体化 JavaScript 运行时。

以开发模式运行

对于开发,您可以直接使用 Bun 运行服务器:

bun run index.ts

执照

[在此添加您的许可证信息]

贡献

[在此处添加贡献指南]

-
security - not tested
F
license - not found
-
quality - not tested

模型上下文协议服务器可帮助 AI 代码编辑器在代码库中定位 TypeScript 符号定义,对于查找导入的符号和类的原始定义特别有用。

  1. Features
    1. Prerequisites
      1. Installation
        1. Installing via Smithery
        2. Manual Installation
      2. Usage
        1. Tool Description
        2. Input Parameters
        3. Examples
        4. Response Format
        5. Claude Desktop Example
      3. Development
        1. Running in Development Mode
      4. License
        1. Contributing
          ID: axtdomofwg