think-tool-mcp
Version:
An MCP server implementing the think tool for Claude and other LLMs
78 lines (77 loc) • 3.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThinkToolServer = void 0;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const zod_1 = require("zod");
class ThinkToolServer {
constructor(serverName = "think-tool") {
this.thoughtsLog = [];
// Initialize MCP server
this.mcp = new mcp_js_1.McpServer({
name: serverName,
version: "0.1.0"
});
// Register tools
this.registerTools();
}
registerTools() {
// Register the think tool
this.mcp.tool("think", `Use this tool to think about something. It will not obtain new information or change anything, but just append the thought to the log. Use it when complex reasoning or cache memory is needed.
Args:
thought: A thought to think about. This can be structured reasoning, step-by-step analysis, policy verification, or any other mental process that helps with problem-solving.`, { thought: zod_1.z.string() }, async ({ thought }) => {
// Log the thought with a timestamp
const timestamp = new Date().toISOString();
this.thoughtsLog.push({
timestamp,
thought
});
// Return a confirmation
return {
content: [{
type: "text",
text: thought.length > 50
? `Thought recorded: ${thought.substring(0, 50)}...`
: `Thought recorded: ${thought}`
}]
};
});
// Register the get_thoughts tool
this.mcp.tool("get_thoughts", `Retrieve all thoughts recorded in the current session.
This tool helps review the thinking process that has occurred so far.`, {}, async () => {
if (this.thoughtsLog.length === 0) {
return {
content: [{
type: "text",
text: "No thoughts have been recorded yet."
}]
};
}
const formattedThoughts = this.thoughtsLog.map((entry, index) => `Thought #${index + 1} (${entry.timestamp}):\n${entry.thought}\n`);
return {
content: [{
type: "text",
text: formattedThoughts.join("\n")
}]
};
});
// Register the clear_thoughts tool
this.mcp.tool("clear_thoughts", `Clear all recorded thoughts from the current session.
Use this to start fresh if the thinking process needs to be reset.`, {}, async () => {
const count = this.thoughtsLog.length;
this.thoughtsLog = [];
return {
content: [{
type: "text",
text: `Cleared ${count} recorded thoughts.`
}]
};
});
}
async run() {
const serverTransport = new stdio_js_1.StdioServerTransport();
await this.mcp.connect(serverTransport);
}
}
exports.ThinkToolServer = ThinkToolServer;
//# sourceMappingURL=server.js.map