向量搜索服务器

一个基于Go的向量搜索服务器,使用Pinecone和OpenAI实现向量搜索功能。

  • by Akhildas-ts
  • Go
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Akhildas-ts/mcp-go-server-ak

使用说明

MCP矢量搜索服务器

基于Go的服务器,使用Pinecone和OpenAI实现矢量搜索功能。

设置

1.环境变量

复制示例环境文件并配置API密钥:

# Copy the example environment file
cp env.example .env

# Edit the .env file with your actual API keys
nano .env

你的 .env 文件应包含以下变量:

# Server Configuration
PORT=8081
JWT_SECRET=your-jwt-secret-key-here

# Pinecone Configuration (Required)
PINECONE_API_KEY=your-pinecone-api-key-here
PINECONE_ENVIRONMENT=your-pinecone-environment
PINECONE_INDEX_NAME=your-pinecone-index-name
PINECONE_HOST=your-pinecone-host-url

# OpenAI Configuration (Required)
OPENAI_API_KEY=your-openai-api-key-here

# GitHub OAuth Configuration (Optional for development)
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
GITHUB_OAUTH_REDIRECT_URL=http://localhost:8081/auth/callback

# MCP Configuration (Optional)
MCP_SECRET_TOKEN=your-mcp-secret-token-here

⚠️ 重要提示: 永远不要承诺你的 .env 文件到版本控制。已添加到 .gitignore 以防止意外犯罪。

2.必需的API密钥

您需要获得以下API密钥:

  1. 松果API密钥:

    • 注册地址: 松果
    • 创建索引并获取API密钥
    • 集 PINECONE_API_KEY, PINECONE_INDEX_NAME,以及 PINECONE_HOST
  2. OpenAI API密钥:

    • 注册地址: OpenAI
    • 从仪表板获取API密钥
    • 集 OPENAI_API_KEY

3.运行应用程序

# Install dependencies
go mod tidy

# Run the application
go run main.go

服务器将从端口8081(或.env文件中指定的端口)启动。

API终点

公众:

  • 健康检查: GET /health
  • 身份验证: GET /auth/login, GET /auth/callback

受保护(需要JWT Authorization: Bearer <token> 或 这个 X-MCP-Token 服务令牌):

  • 搜索: POST /search
  • 使用AI摘要搜索: POST /search/summary
  • 聊天: POST /chat
  • 索引存储库: POST /index
  • 列出存储库: GET /repositories
  • 轮廓: GET /profile

MCP 服务器

MCP(模型上下文协议)服务器作为第二个二进制文件包含在此 模块。它通过stdio说出JSON-RPC,并将工具调用转发到上面的API, 通过身份验证 MCP_SECRET_TOKEN 服务令牌。

# Build the MCP server binary
go build -o bin/mcp ./cmd/mcp

它公开了三个工具-- chat, vectorSearch 和 indexRepository --加上a health 方法,并响应 getServerInfo 和 listOfferings.

游标/MCP客户端配置

将以下内容添加到MCP客户端配置中(例如。 ~/.cursor/mcp.json), 指向 command 在构建的二进制文件中:

{
  "mcp-vector-search": {
    "command": "/absolute/path/to/bin/mcp",
    "env": {
      "GO_SERVER_URL": "http://localhost:8081",
      "MCP_SECRET_TOKEN": "your-mcp-secret-token-here"
    }
  }
}

发展

对于开发,您可以为可选字段设置虚拟值,但是 PINECONE_API_KEY 和 OPENAI_API_KEY 应用程序启动所必需的。

提交前运行检查:

gofmt -l .        # should print nothing
go vet ./...
go build ./...
go test ./...