io.github.toby/mirror-mcp

编码与调试

by toby

Mirror gives LLMs the ability to self-reflect with MCP sampling.

什么是 io.github.toby/mirror-mcp

Mirror gives LLMs the ability to self-reflect with MCP sampling.

README

mirror-mcp

npm version License: MIT

A Model Context Protocol (MCP) server that provides a reflect tool, enabling LLMs to engage in self-reflection and introspection through recursive questioning and MCP sampling.

Overview

mirror-mcp allows AI models to "look at themselves" by providing a reflection mechanism. When an LLM uses the reflect tool, it can pose questions to itself and receive answers through the Model Context Protocol's sampling capabilities. This creates a powerful feedback loop for self-analysis, reasoning validation, and iterative problem-solving.

Features

  • 🪞 Self-Reflection Tool: Enables LLMs to ask themselves questions and receive computed responses
  • 🔄 MCP Sampling Integration: Uses the Model Context Protocol's sampling mechanism for responses
  • 📦 npm Installable: Easy installation and deployment
  • Lightweight: Minimal dependencies and fast startup
  • 🔧 Configurable: Customizable reflection parameters and sampling options

Installation

Quick Install for VS Code

Install in VS Code Install in VS Code Insiders

MCP Host Configuration

For other MCP-compatible clients, add the following configuration:

json
{
  "type": "stdio",
  "command": "npx", 
  "args": ["mirror-mcp@latest"]
}

Via npm

bash
npm install -g mirror-mcp

Via npx (no installation required)

bash
npx mirror-mcp

From Source

bash
git clone https://github.com/toby/mirror-mcp.git
cd mirror-mcp
npm install
npm run build
npm start

API Reference

Tools

reflect

Enables the LLM to ask itself a question and receive a response through MCP sampling. The tool supports custom system and user prompts to help the LLM self-direct what kind of response it gets.

Self-Direction with Custom Prompts:

  • System Prompt: Define the role or perspective for the reflection (e.g., "expert coach", "critical thinker", "creative problem solver")
  • User Prompt: Specify the format, structure, or focus of the reflection response
  • Default Behavior: When no custom prompts are provided, uses built-in reflection guidance focused on strengths, weaknesses, assumptions, and alternative perspectives

Parameters:

  • question (string, required): The question the LLM wants to ask itself
  • context (string, optional): Additional context for the reflection
  • system_prompt (string, optional): Custom system prompt to direct the reflection approach
  • user_prompt (string, optional): Custom user prompt to replace the default reflection instructions
  • max_tokens (number, optional): Maximum tokens for the response (default: 500)
  • temperature (number, optional): Sampling temperature (default: 0.8)

Example:

json
{
  "name": "reflect",
  "arguments": {
    "question": "How confident am I in my previous analysis of the data?",
    "context": "Previous analysis showed a 23% increase in user engagement",
    "max_tokens": 300,
    "temperature": 0.6
  }
}

Example with custom prompts:

json
{
  "name": "reflect",
  "arguments": {
    "question": "What are the potential weaknesses in my reasoning?",
    "system_prompt": "You are an expert critical thinking coach helping to identify logical fallacies and reasoning gaps.",
    "user_prompt": "Analyze my reasoning step-by-step and provide specific examples of potential weaknesses or blind spots.",
    "context": "Working on a complex machine learning model evaluation",
    "max_tokens": 400,
    "temperature": 0.7
  }
}

Response:

json
{
  "reflection": "Upon reflection, my confidence in the 23% engagement increase analysis is moderate to high. The data sources appear reliable, and the methodology follows standard practices. However, I should consider potential confounding variables such as seasonal effects or concurrent marketing campaigns that might influence the results.",
  "metadata": {
    "tokens_used": 67,
    "reflection_time_ms": 1240
  }
}

Architecture & Rationale

Design Philosophy

mirror-mcp is built on the principle that self-reflection is crucial for robust AI reasoning. By enabling models to question their own outputs and reasoning processes, we create opportunities for:

  • Error Detection: Models can identify potential flaws in their logic
  • Confidence Calibration: Self-assessment helps gauge certainty levels
  • Iterative Improvement: Reflective questioning can lead to better solutions
  • Metacognitive Awareness: Understanding of the model's own reasoning process

Technical Architecture

code
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   LLM Client    │───▶│   mirror-mcp    │───▶│  MCP Sampling   │
│                 │    │                 │    │   Infrastructure │
│ Calls reflect() │    │ Processes       │    │                 │
│                 │◀───│ reflection      │◀───│ Returns response│
└─────────────────┘    └─────────────────┘    └─────────────────┘

Key Components

  1. Reflection Engine: Processes incoming self-directed questions
  2. Sampling Interface: Interfaces with MCP's sampling capabilities
  3. Context Manager: Maintains conversation context for coherent reflections
  4. Response Formatter: Structures reflection responses for optimal consumption

Why MCP?

The Model Context Protocol provides a standardized way for AI models to connect with external resources and tools. By implementing mirror-mcp as an MCP server, we ensure:

  • Interoperability: Works with any MCP-compatible client
  • Standardization: Follows established protocols for tool integration
  • Scalability: Can be deployed alongside other MCP servers
  • Future-Proofing: Benefits from ongoing MCP ecosystem development

Sampling Strategy

The reflection mechanism leverages MCP's sampling capabilities to generate thoughtful responses. The sampling process:

  1. Takes the self-directed question as a prompt
  2. Applies configurable sampling parameters (temperature, max tokens)
  3. Generates a response using the underlying model
  4. Returns the reflection with appropriate metadata

This approach ensures that reflections are generated using the same model capabilities as the original reasoning, creating authentic self-assessment.

Development

Prerequisites

  • Node.js 18 or higher
  • npm or yarn
  • TypeScript (for development)

Development Setup

bash
git clone https://github.com/toby/mirror-mcp.git
cd mirror-mcp
npm install
npm run dev

Testing

bash
npm test

Building

bash
npm run build

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Areas for Contribution

  • Enhanced reflection strategies
  • Additional sampling parameters
  • Performance optimizations
  • Documentation improvements
  • Test coverage expansion

Related Projects

  • Model Context Protocol: The foundational protocol specification
  • MCP Ecosystem: Various other MCP servers and tools

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • The Model Context Protocol team for creating the foundational specification
  • The broader AI research community working on metacognition and self-reflection
  • Contributors and early adopters who help shape this tool

"The unexamined life is not worth living" - Socrates

Enable your AI models to examine their own reasoning with mirror-mcp.

常见问题

io.github.toby/mirror-mcp 是什么?

Mirror gives LLMs the ability to self-reflect with MCP sampling.

相关 Skills

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描164.6k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描164.6k

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描164.6k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
88.1k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
58.6k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
49.4k

评论