UNPKG

@mettamatt/code-reasoning

Version:

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

88 lines (87 loc) 3.46 kB
#!/usr/bin/env node /** * @fileoverview Code Reasoning MCP Server Implementation. * * This server provides a tool for reflective problem-solving in software development, * allowing decomposition of tasks into sequential, revisable, and branchable thoughts. * It adheres to the Model Context Protocol (MCP) using SDK version 1.18.1 and is designed * to integrate seamlessly with Claude Desktop or similar MCP-compliant clients. * * ## Key Features * - Processes "thoughts" in structured JSON with sequential numbering * - Supports advanced reasoning patterns through branching and revision semantics * - Branching: Explore alternative approaches from any existing thought * - Revision: Correct or update earlier thoughts when new insights emerge * - Implements MCP capabilities for tools, resources, and prompts * - Relies on the standard StdioServerTransport provided by the MCP SDK * - Provides detailed validation and error handling with helpful guidance * - Logs thought evolution to stderr for debugging and visibility * * ## Usage in Claude Desktop * - In your Claude Desktop settings, add a "tool" definition referencing this server * - Ensure the tool name is "code-reasoning" * - Configure Claude to use this tool for complex reasoning and problem-solving tasks * - Upon connecting, Claude can call the tool with arguments matching the * `ThoughtData` interface defined in this file * * ## MCP Protocol Communication * - IMPORTANT: Local MCP servers must never log to stdout (standard output) * - All logging must be directed to stderr using console.error() instead of console.log() * - The stdout channel is reserved exclusively for JSON-RPC protocol messages * - Using console.log() or console.info() will cause client-side parsing errors * * ## Example Thought Data * ```json * { * "thought": "Start investigating the root cause of bug #1234", * "thought_number": 1, * "total_thoughts": 5, * "next_thought_needed": true * } * ``` * * @version 0.7.0 * @mcp-sdk-version 1.18.1 */ import { z } from 'zod'; export declare enum LogLevel { ERROR = 0, WARN = 1, INFO = 2, DEBUG = 3 } declare const StrictThoughtSchema: z.ZodObject<{ thought: z.ZodString; thought_number: z.ZodNumber; total_thoughts: z.ZodNumber; next_thought_needed: z.ZodBoolean; is_revision: z.ZodOptional<z.ZodBoolean>; revises_thought: z.ZodOptional<z.ZodNumber>; branch_from_thought: z.ZodOptional<z.ZodNumber>; branch_id: z.ZodOptional<z.ZodString>; needs_more_thoughts: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { thought: string; thought_number: number; total_thoughts: number; next_thought_needed: boolean; is_revision?: boolean | undefined; revises_thought?: number | undefined; branch_from_thought?: number | undefined; branch_id?: string | undefined; needs_more_thoughts?: boolean | undefined; }, { thought: string; thought_number: number; total_thoughts: number; next_thought_needed: boolean; is_revision?: boolean | undefined; revises_thought?: number | undefined; branch_from_thought?: number | undefined; branch_id?: string | undefined; needs_more_thoughts?: boolean | undefined; }>; export type ThoughtData = z.infer<typeof StrictThoughtSchema>; export type ValidatedThoughtData = ThoughtData; export declare function runServer(debugFlag?: boolean): Promise<void>; export {};