MCP Sage

MCP Sage

An MCP server that provides tools for getting second opinions or detailed code reviews from Gemini 2.5 Pro by embedding file contents in prompts, allowing it to handle large codebases with extensive context.

Category
访问服务器

README

mcp-sage

An MCP (Model Context Protocol) server that provides tools for sending prompts to another LLM (currently only Gemini 2.5 Pro) that embed all referenced filepaths (recursively for folders) in the prompt. Useful for getting second opinions or detailed code reviews from a model that can handle tons of context accurately.

Rationale

I make heavy use of Claude Code. It's a great product that works well for my workflow. Newer models with large amounts of context seem really useful though for dealing with more complex codebases where more context is needed. This lets me continue to use Claude Code as a development tool while leveraging the large context of Gemini 2.5 Pro to augment Claude Code's limited context.

Inspiration

This project draws inspiration from two other open source projects:

Overview

This project implements an MCP server that exposes two tools:

second-opinion

  1. Takes a prompt and a list of file/dir paths as input
  2. Packs the files into a structured XML format
  3. Checks if the combined content is within Gemini's token limit (1M tokens)
  4. Sends the combined prompt + context to Gemini 2.5 Pro
  5. Returns the model's response

expert-review

  1. Takes an instruction for code changes and a list of file/dir paths as input
  2. Packs the files into a structured XML format
  3. Checks if the combined content is within Gemini's token limit (1M tokens)
  4. Creates a specialized prompt instructing the model to format responses using SEARCH/REPLACE blocks
  5. Sends the combined context + instruction to Gemini 2.5 Pro
  6. Returns edit suggestions formatted as SEARCH/REPLACE blocks for easy implementation

Prerequisites

  • Node.js (v18 or later)
  • A Google Gemini API key

Installation

# Clone the repository
git clone https://github.com/your-username/mcp-sage.git
cd mcp-sage

# Install dependencies
npm install

# Build the project
npm run build

Environment Variables

Set the following environment variable:

  • GEMINI_API_KEY: Your Google Gemini API key

Usage

After building with npm run build, add the following to your MCP configuration:

GEMINI_API_KEY=XXX node /path/to/this/repo/dist/index.js

Prompting

To get a second opinion on something just ask for a second opinion.

To get a code review, ask for a code review or expert review.

Both of these benefit from providing paths of files that you wnat to be included in context, but if omitted the host LLM will probably infer what to include.

Debugging and Monitoring

The server provides detailed monitoring information via the MCP logging capability. These logs include:

  • Token usage statistics (tokens used vs. token limit)
  • Number of files and documents included in the request
  • Request processing time metrics
  • Error information when token limits are exceeded

Logs are sent via the MCP protocol's notifications/message method, ensuring they don't interfere with the JSON-RPC communication. MCP clients with logging support will display these logs appropriately.

Example log entries:

Token usage: 1,234 / 1,000,000 tokens (0.12%)
Files included: 3, Document count: 3
Sending request to Gemini with 1,234 tokens...
Received response from Gemini in 982ms

Using the Tools

second-opinion Tool

The second-opinion tool accepts the following parameters:

  • prompt (string, required): The prompt to send to Gemini
  • paths (array of strings, required): List of file paths to include as context

Example MCP tool call (using JSON-RPC 2.0):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "second-opinion",
    "arguments": {
      "prompt": "Explain how this code works",
      "paths": ["path/to/file1.js", "path/to/file2.js"]
    }
  }
}

expert-review Tool

The expert-review tool accepts the following parameters:

  • instruction (string, required): The specific changes or improvements needed
  • paths (array of strings, required): List of file paths to include as context

Example MCP tool call (using JSON-RPC 2.0):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "expert-review",
    "arguments": {
      "instruction": "Add error handling to the function",
      "paths": ["path/to/file1.js", "path/to/file2.js"]
    }
  }
}

The response will contain SEARCH/REPLACE blocks that you can use to implement the suggested changes:

<<<<<<< SEARCH
function getData() {
  return fetch('/api/data')
    .then(res => res.json());
}
=======
function getData() {
  return fetch('/api/data')
    .then(res => {
      if (!res.ok) {
        throw new Error(`HTTP error! Status: ${res.status}`);
      }
      return res.json();
    })
    .catch(error => {
      console.error('Error fetching data:', error);
      throw error;
    });
}
>>>>>>> REPLACE

Running the Tests

To test the tools:

# Test the second-opinion tool
GEMINI_API_KEY=your_api_key_here node test/run-test.js

# Test the expert-review tool
GEMINI_API_KEY=your_api_key_here node test/test-expert.js

Project Structure

  • src/index.ts: The main MCP server implementation with tool definitions
  • src/pack.ts: Tool for packing files into a structured XML format
  • src/tokenCounter.ts: Utilities for counting tokens in a prompt
  • src/gemini.ts: Gemini API client implementation
  • test/run-test.js: Test for the second-opinion tool
  • test/test-expert.js: Test for the expert-review tool

License

ISC

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选