Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@mettamatt/code-reasoning

mettamatt771MIT0.7.0TypeScript support: included

Enhanced MCP server for code reasoning using sequential thinking methodology, optimized for programming tasks

mcp, model-context-protocol, code-reasoning, sequential-thinking, programming, claude, ai, coding-assistant, reasoning, problem-solving, systematic-thinking, code-analysis, debugging, anthropic, llm-tools, branching, revision, reflective-thinking

readme

Code Reasoning MCP Server

A Model Context Protocol (MCP) server that enhances Claude's ability to solve complex programming tasks through structured, step-by-step thinking.

Code Reasoning Server MCP server

npm version License: MIT CI

Quick Installation

  1. Configure Claude Desktop by editing:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
    {
      "mcpServers": {
        "code-reasoning": {
          "command": "npx",
          "args": ["-y", "@mettamatt/code-reasoning"]
        }
      }
    }
  2. Configure VS Code:

{
  "mcp": {
    "servers": {
      "code-reasoning": {
        "command": "npx",
        "args": ["-y", "@mettamatt/code-reasoning"]
      }
    }
  }
}

Usage

  1. To trigger this MCP, append this to your chat messages:

    Use sequential thinking to reason about this.
  2. Use ready-to-go prompts that trigger Code-Reasoning:

Code Reasoning Prompts

  • Click the "+" icon in the Claude Desktop chat window, or in Claude Code type /help to see the specific commands.
  • Select "Add from Code Reasoning" from the available tools
  • Choose a prompt template and fill in the required information
  • Submit the form to add the prompt to your chat message and hit return

See the Prompts Guide for details on using the prompt templates.

Command Line Options

  • --debug: Enable detailed logging
  • --help or -h: Show help information

Key Features

  • Programming Focus: Optimized for coding tasks and problem-solving
  • Structured Thinking: Break down complex problems into manageable steps
  • Thought Branching: Explore multiple solution paths in parallel
  • Thought Revision: Refine earlier reasoning as understanding improves
  • Safety Limits: Automatically stops after 20 thought steps to prevent loops
  • Ready-to-Use Prompts: Pre-defined templates for common development tasks

Documentation

Detailed documentation available in the docs directory:

Project Structure

├── index.ts                  # Entry point
├── src/                      # Implementation source files
└── test/                     # Testing framework

Prompt Evaluation

The Code Reasoning MCP Server includes a prompt evaluation system that assesses Claude's ability to follow the code reasoning prompts. This system allows:

  • Testing different prompt variations against scenario problems
  • Verifying parameter format adherence
  • Scoring solution quality
  • Generating comprehensive reports

To use the prompt evaluation system, run:

npm run eval

Prompt Comparison and Development

Significant effort went into developing the optimal prompt for the Code Reasoning server. The current implementation uses the HYBRID_DESIGN prompt, which emerged as the winner from our evaluation process.

We compared four different prompt designs:

Prompt Design Description
SEQUENTIAL The original sequential thinking prompt design
DEFAULT The baseline prompt previously used in the server
CODE_REASONING_0_30 An experimental variant focusing on code-specific reasoning
HYBRID_DESIGN A refined design incorporating the best elements of other approaches

Our evaluation across seven diverse programming scenarios showed that HYBRID_DESIGN outperformed other prompts:

Scenario HYBRID_DESIGN CODE_REASONING_0_30 DEFAULT SEQUENTIAL
Algorithm Selection 87% 82% 88% 82%
Bug Identification 87% 91% 88% 92%
Multi-Stage Implementation 83% 67% 79% 82%
System Design Analysis 82% 87% 78% 82%
Code Debugging Task 92% 87% 92% 92%
Compiler Optimization 83% 78% 67% 73%
Cache Strategy 86% 88% 82% 87%
Average 86% 83% 82% 84%

The HYBRID_DESIGN prompt marginally demonstrated both the highest average solution quality (86%) and the most consistent performance across all scenarios, with no scores below 80%. It also prodouced the most thoughts. The src/server.ts file has been updated to use this optimal prompt design.

Personally, I think the biggest improvement was adding this to the end of the prompt: "✍️ End each thought by asking: "What am I missing or need to reconsider?"

See Testing Framework for more details on the prompt evaluation system.

License

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

changelog

Changelog

0.7.0 (2025-05-10)

Features

  • Added comprehensive MCP prompts system with predefined templates
    • Includes architecture-decision, bug-analysis, code-review, feature-planning, and refactoring-plan prompts
    • The last prompt value is saved so that it can be used again but it will not show until Claude Desktop and Claude Code implement MCP CompleteRequestSchema. See https://github.com/anthropics/claude-code/issues/986
    • Added support for custom prompt templates via JSON files
    • Added Zod-based input sanitization to template processing

0.6.2 (2025-05-04)

Features

  • Added tool annotations support to better inform clients about the tool's behavior
  • Updated MCP SDK version reference to 1.11.0

Improvements

  • Updated ESLint ecosystem to major new versions
    • ESLint: 8.57.1 → 9.26.0
    • @typescript-eslint/parser: 7.18.0 → 8.31.1
    • @typescript-eslint/eslint-plugin: 7.18.0 → 8.31.1
  • Added ESLint v9 flat config support via eslint.config.js
  • Removed obsolete .eslintrc.json configuration
  • Added GitHub Actions CI/CD workflows and contribution templates
  • Added CI badge and Contributing section to README

0.6.1 (2025-05-02)

Bug Fixes

  • Fixed "Maximum call stack size exceeded" error in FilteredStdioServerTransport by preventing recursive stdout.write calls
  • Improved stdout filtering mechanism to avoid circular references when filtering non-JSON output

Improvements

  • Doubled default operation timeout from 30s to 60s for better handling of complex reasoning tasks

0.6.0 (2025-04-30)

Features

  • Upgraded MCP SDK from 0.5.0 to 1.10.2 for enhanced protocol compatibility
  • Added support for additional protocol capabilities (resources, prompts)
  • Implemented custom FilteredStdioServerTransport for improved stability
  • Added handlers for ListResourcesRequestSchema and ListPromptsRequestSchema

Technical Improvements

  • Leveraged zodToJsonSchema utility for schema generation rather than manual creation
  • Documented intent of empty resource and prompt handlers to prevent Claude Desktop errors
  • Refined JSON detection logic in FilteredStdioServerTransport to handle array literals
  • Simplified type aliases by using direct SDK types for better maintainability
  • Improved file header documentation with MCP SDK version information and clearer feature descriptions
  • Updated type definitions for newer SDK compatibility
  • Added zod-to-json-schema dependency
  • Reorganized server.ts with clear section headers for better code organization
  • Enhanced code performance with cached JSON schema and optimized validation
  • Improved type safety with readonly properties and Map instead of object literals

0.5.0 (2025-04-30)

Features

  • Updated core prompt to use HYBRID_DESIGN for better reasoning performance
  • Added prompt evaluation system with documentation and examples
  • Enhanced end-to-end test framework
  • Increased maxThoughtLength for more complex reasoning tasks

0.4.0 (earlier release)

Initial documented version.