智能文档检索服务

一个基于模型上下文协议(MCP)的服务器,提供跨多个技术领域的智能文档检索功能。

  • by deep-poharkar
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 deep-poharkar/mcp-server

使用说明

文档中心MCP服务器

用于跨多个技术领域的智能文档检索的模型上下文协议(MCP)服务器。

概述

该项目实现了一个MCP服务器,为技术查询提供有针对性的文档检索。它使用混合方法来:

  1. 确定查询的技术领域(React、Node.js、Python)
  2. 从查询中提取特定主题
  3. 构建精确的文档URL
  4. 获取并返回最相关的文档

该服务器使用TypeScript和MCP SDK构建,为AI模型访问文档资源提供了一个标准化的接口。

特性

  • 领域分类:自动识别查询是关于React、Node.js、Python还是一般主题
  • 主题提取:使用正则表达式模式匹配来识别查询中的特定技术概念
  • URL构造:根据确定的主题构建有针对性的文档URL
  • 多个文档来源:支持React、Node.js、Python的文档,并可扩展到其他领域
  • 标准化接口:实现模型上下文协议,以实现与MCP兼容客户端的互操作性

安装

# Clone the repository
git clone https://github.com/yourusername/mcp-server.git
cd mcp-server

# Install dependencies
npm install

# Build the project
npm run build

用法

运行服务器

node build/index.js

测试主题提取

该项目包括一个测试脚本,用于演示主题提取和URL构建的工作原理:

# Build the test script
npx tsc src/test.ts --outDir build

# Run the test
node build/test.js

与客户整合

服务器可以与任何兼容MCP的客户端集成。下面是一个客户端如何与服务器交互的示例:

// Example client code (not included in this project)
const client = new McpClient();
const result = await client.callTool("fetch-documentation", {
  query: "How do I use useState hook in React?",
});

console.log(result);
// Output: {
//   domain: "react-docs",
//   topics: ["useState", "state"],
//   specificUrl: "https://react.dev/reference/react/useState",
//   content: "...",
//   source: "https://react.dev/reference/react/useState"
// }

项目结构

  • src/index.ts -主服务器实现
  • src/test.ts -主题提取和URL构建的测试脚本
  • build/ -编译的JavaScript输出
  • package.json -项目配置和依赖关系

可用工具

服务器公开了以下工具:

确定域

确定查询属于哪个技术域。

{
  query: string; // The user query to classify
}

退货:

{
  domain: string; // The identified domain
  confidence: string; // "high" or "low"
}

提取主题

从给定域的查询中提取特定主题。

{
  query: string; // The user query to analyze
  domain: string; // The technical domain to extract topics for
}

退货:

{
  topics: string[]; // Array of identified topics
  count: number; // Number of topics found
}

获取文档

根据查询和域获取文档。

{
  query: string; // The user query
  domain?: string; // Optional domain override
}

退货:

{
  domain: string; // The identified domain
  topics: string[]; // Array of identified topics
  specificUrl: string | null; // The constructed URL if available
  content: string; // The fetched documentation content
  source: string; // The source URL
}

可用资源

服务器提供以下文档资源:

  • react-docs -React.js文档
  • node-docs -Node.js文档
  • python-docs -Python文档
  • general -域不清楚时的一般文档

扩展服务器

添加新域名

要添加对新技术领域的支持,请执行以下操作:

  1. 将域关键字添加到 domainKeywords 对象在 determineDomain 函数
  2. 将主题模式添加到 topicPatterns 对象在 extractTopics 函数
  3. 将URL构造逻辑添加到 constructSpecificUrl 函数
  4. 在服务器配置中添加新的资源处理程序

改进主题提取

可以通过以下方式改进主题提取:

  1. 增强现有主题的正则表达式模式
  2. 向现有域添加新主题
  3. 实施更复杂的NLP技术进行主题提取

许可证

麻省理工学院

贡献

欢迎投稿!请随时提交拉取请求。