npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zyw-ai-mcp-repo

v0.1.8

Published

MCP服务器托管平台,用于管理和执行MCP(Model Context Protocol)服务器,以及用于实现MCP server管理的客户端组件,更新了authjs配置,设置了全局配置,使用ai sdk @ai-sdk/openai代替openai sdk,更新了prisma的配置,添加了向量数据库的配置,更新了mcp server manager的代码,添加了向量数据库的配置,更新了mcp server manager的代码,添加了向量数据库的配置,优化了向量嵌入的token长度。

Readme

ZYW-AI-MCP-REPO - 模型上下文协议(MCP)服务器托管库

这是一个用于托管和管理MCP(Model Context Protocol)服务器的TypeScript库,基于Next.js 14构建。该库提供了一套完整的工具,用于管理MCP服务器、创建AI任务流程、存储和检索向量嵌入,以及执行复杂的AI任务序列。

特性

  • 🚀 MCP服务器管理 - 添加、更新、删除和运行MCP服务器
  • 🔄 任务流程系统 - 定义和执行包含多个步骤的AI任务
  • 🧠 向量嵌入和语义搜索 - 存储和检索基于相似度的内容
  • 🤖 AI代理集成 - 使用OpenAI进行嵌入处理和任务分解
  • 📊 数据库支持 - 使用Prisma ORM和PostgreSQL存储所有数据
  • 🎨 用户界面组件 - 提供基于Mantine UI的客户端组件

安装

npm install zyw-ai-mcp-repo

基本用法

import { config, setupMCPServer, createTask, executeTask } from 'zyw-ai-mcp-repo';

// 配置库
config({
  openai: {
    apiKey: process.env.OPENAI_API_KEY,
    model: 'gpt-4o'
  },
  databaseUrl: process.env.DATABASE_URL
});

// 添加MCP服务器
const server = await setupMCPServer({
  name: 'Playwright Browser',
  githubUrl: 'https://github.com/example/mcp-playwright-browser',
  description: '提供浏览器自动化能力的MCP服务器'
});

/**
 * 注意:GitHub URL格式
 * 
 * 添加MCP服务器时,请确保使用正确的GitHub仓库URL格式:
 * 正确:https://github.com/用户名/仓库名
 * 错误:https://github.com/用户名/仓库名/tree/main/子目录
 * 
 * 系统会自动处理和规范化URL,但最好提供正确的仓库根URL。
 */

// 创建任务
const task = await createTask({
  name: '网页内容摘要',
  description: '访问网页并生成内容摘要',
  originalPrompt: '访问URL,提取主要内容并生成摘要'
});

// 执行任务
const result = await executeTask(task.id);
console.log(result);

客户端组件

该库提供了一系列预构建的React客户端组件,用于快速创建MCP服务器和任务管理界面:

// MCP服务器组件
import { MCPServerTabs, ExecutionForm } from 'zyw-ai-mcp/components/client/mcp-server';

// 任务组件
import { TaskTabs, AITaskDecomposer } from 'zyw-ai-mcp/components/client/task';

// UI工具组件
import { StatusBadge, SearchInput, PaginationControl } from 'zyw-ai-mcp/components/client/ui';

// 使用示例
export default function MCPServerPage() {
  return (
    <div className="container mx-auto p-4">
      <MCPServerTabs />
    </div>
  );
}

项目结构

zyw-ai-mcp/
├── src/
│   ├── actions/             # 服务器端操作
│   │   ├── mcp-server-actions.ts
│   │   └── task-actions.ts
│   ├── components/
│   │   ├── client/          # 客户端组件
│   │   │   ├── mcp-server/  # MCP服务器组件
│   │   │   ├── task/        # 任务组件
│   │   │   └── ui/          # UI工具组件
│   │   ├── server/          # 服务器端组件
│   │   └── types.ts
│   ├── lib/
│   │   ├── ai/              # AI工具
│   │   ├── db/              # 数据库工具
│   │   ├── mcp/             # MCP服务器管理
│   │   └── tasks/           # 任务管理
│   └── types/               # 类型定义
├── prisma/                  # Prisma模型和迁移
└── public/                  # 静态资源

API文档

配置

config({
  // 数据库配置
  prisma?: PrismaClient;
  databaseUrl?: string;
  
  // OpenAI配置
  openai?: {
    apiKey?: string;
    model?: string; // 默认: 'gpt-4o'
    temperature?: number; // 默认: 0.7
    maxTokens?: number; // 默认: 2000
    embeddingModel?: string; // 默认: 'text-embedding-3-large'
  };
  
  // MCP服务器配置
  mcpServers?: {
    defaultTimeout?: number; // 默认: 30000ms
    maxConcurrentServers?: number; // 默认: 5
    tempDir?: string; // 默认: './.mcp-temp'
  };
  
  // 向量搜索配置
  vectorSearch?: {
    dimensions?: number; // 默认: 1536
    similarityThreshold?: number; // 默认: 0.8
  };
});

MCP服务器管理

// 添加MCP服务器
const server = await setupMCPServer({
  name: string;
  githubUrl: string;
  description?: string;
  npmPackage?: string;
});

// 获取MCP服务器
const server = await getMCPServer(id);

// 更新MCP服务器
await updateMCPServer(id, {
  name?: string;
  description?: string;
  npmPackage?: string;
});

// 删除MCP服务器
await deleteMCPServer(id);

// 运行MCP服务器
const process = await runMCPServer(id, {
  prompt: string;
  context?: string;
  // 其他配置选项...
});

任务管理

// 创建任务
const task = await createTask({
  name: string;
  description?: string;
  originalPrompt?: string;
});

// 创建流程
const flow = await createFlow({
  taskId: string;
  name: string;
  description?: string;
  order: number;
  prompt: string;
});

// 添加MCP服务器到流程
const flowMCPServer = await addMCPServerToFlow(
  flowId: string,
  mcpServerId: string,
  order: number
);

// 执行任务
const result = await executeTask(taskId);

向量嵌入和搜索

// 创建嵌入向量
const embedding = await createEmbedding(text);

// 搜索相似向量
const results = await searchSimilarVectors(embedding, threshold, limit);

// 按MCP服务器ID搜索向量
const results = await searchSimilarVectorsByMCPServer(embedding, mcpServerId);

// 基于文本查询搜索
const results = await searchSimilarContent(query);

// 根据文本查询相关的MCP服务器
const serverIds = await searchRelevantMCPServers(query);

数据库设置

  1. 安装PostgreSQL
  2. 创建.env文件并设置数据库连接:
DATABASE_URL="postgresql://username:password@localhost:5432/mcp_db?schema=public"
  1. 运行数据库迁移:
npx prisma migrate dev --name init

authjs设置

允许宿主项目通过config({auth:hostAuth})方式指定auth: 修改了src/auth.ts文件: 将配置部分与实例创建分离 添加了config函数,支持传入外部auth实例 添加了getAuth函数,返回当前配置的auth实例 增加了初始化状态检查,防止重复配置 更新了src/actions/mcp-server-actions.ts: 修改导入,使用getAuth函数获取当前auth实例 调用方式改为getAuth()() 更新了src/index.ts入口文件: 使用authConfig名称导出auth配置函数,避免与库本身的config冲突 添加了getAuth函数导出 更新了API路由文件,增加getAuth导入

import { authConfig } from 'zyw-ai-mcp-repo';

// 使用宿主项目的auth实例配置
authConfig({ auth: myHostAuth }); //myHostAuth 一般为@/auth

示例

请查看示例目录获取更多用法示例。

贡献

欢迎提交Pull Request和Issue。

许可证

MIT

向量处理功能

MCP平台支持向量数据处理,可用于语义搜索和相似性匹配,特别适用于推荐相关MCP服务器。

向量嵌入优化

本库在处理向量数据时,会自动优化嵌入内容,避免超出模型token限制:

  • 从README中仅提取标题、介绍和关键段落
  • 从代码文件中仅提取类、函数和导出项的定义
  • 优先处理重要文件,如index、main、api等
  • 限制文件处理数量和内容长度

这种优化不仅降低了token使用量,还提高了相似性搜索的准确性,因为嵌入内容集中在最有代表性的内容上。

PostgreSQL向量扩展

使用向量功能需要在PostgreSQL中安装pgvector扩展:

-- 安装扩展
CREATE EXTENSION IF NOT EXISTS vector;

-- 验证安装
SELECT * FROM pg_extension WHERE extname = 'vector';

基本向量函数

  • createEmbedding(text): 创建文本的向量嵌入表示
  • cosineSimilarity(a, b): 计算两个向量间的余弦相似度

向量搜索

  • searchSimilarContent(query, threshold, limit): 搜索与查询文本相似的内容
  • searchRelevantMCPServers(query, threshold, limit): 查找与查询文本相关的MCP服务器
  • findRelevantMCPServers(content, threshold, limit): 通过语义相似性查找相关服务器

向量记录管理

  • createVectorRecord(content, metadata, mcpServerId): 创建新的向量记录
  • updateVectorRecord(id, content, metadata): 更新现有向量记录
  • setMCPServerVector(serverId, content): 设置MCP服务器的向量表示
  • updateAllMCPServerVectors(): 更新所有MCP服务器的向量表示
  • rebuildServerVectors(serverId?): 重建单个或所有MCP服务器的向量表示

向量数据库操作

由于Prisma目前不完全支持向量字段操作,我们提供了直接操作数据库的函数:

  • insertWithVector({table, data, vectorField, vectorData}): 插入包含向量字段的数据
  • updateWithVector({table, where, data, vectorField, vectorData}): 更新包含向量字段的数据
  • querySimilarVectors({table, vectorField, vectorData, threshold, limit}): 查询相似向量