/**
* Example MCP Client for Sequential Thinking
* This demonstrates how to use the sequential thinking server
*/
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
async function main() {
// Create a client
const client = new Client(
{
name: 'sequential-thinking-client',
version: '1.0.0',
},
{
capabilities: {},
}
);
// Connect to the server
const transport = new StdioClientTransport({
command: 'node',
args: ['../dist/index.js'],
});
await client.connect(transport);
console.log('Connected to Sequential Thinking Server');
// List available tools
const tools = await client.listTools();
console.log('\nAvailable tools:');
tools.tools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
});
// Example: Add sequential thoughts
console.log('\n=== Example: Sequential Problem Solving ===\n');
// Thought 1
const thought1 = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'First, I need to understand the problem: How to build a scalable web application?',
nextThoughtNeeded: true,
thoughtNumber: 1,
totalThoughts: 5,
},
});
console.log('Thought 1:', JSON.parse(thought1.content[0].text).message);
// Thought 2
const thought2 = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'Consider the architecture: Microservices vs Monolithic',
nextThoughtNeeded: true,
thoughtNumber: 2,
totalThoughts: 5,
},
});
console.log('Thought 2:', JSON.parse(thought2.content[0].text).message);
// Thought 3 - Branching
const thought3Branch = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'Alternative: Start with monolithic and migrate to microservices later',
nextThoughtNeeded: true,
thoughtNumber: 3,
totalThoughts: 5,
branchFromThought: 2,
branchId: 'alternative-architecture',
},
});
console.log('Thought 3 (Branch):', JSON.parse(thought3Branch.content[0].text).message);
// Thought 3 - Main path
const thought3 = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'Choose microservices for better scalability and team autonomy',
nextThoughtNeeded: true,
thoughtNumber: 3,
totalThoughts: 5,
},
});
console.log('Thought 3 (Main):', JSON.parse(thought3.content[0].text).message);
// Thought 4
const thought4 = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'Design the tech stack: Node.js services, PostgreSQL, Redis, Docker',
nextThoughtNeeded: true,
thoughtNumber: 4,
totalThoughts: 5,
},
});
console.log('Thought 4:', JSON.parse(thought4.content[0].text).message);
// Thought 5
const thought5 = await client.callTool({
name: 'sequential_thinking',
arguments: {
thought: 'Plan deployment: Kubernetes for orchestration, CI/CD pipeline, monitoring',
nextThoughtNeeded: false,
thoughtNumber: 5,
totalThoughts: 5,
},
});
console.log('Thought 5:', JSON.parse(thought5.content[0].text).message);
// Get the complete sequence
console.log('\n=== Complete Thought Sequence ===\n');
const sequence = await client.callTool({
name: 'get_thought_sequence',
arguments: {},
});
const sequenceData = JSON.parse(sequence.content[0].text);
console.log(`Session: ${sequenceData.sessionId}`);
console.log(`Total thoughts: ${sequenceData.thoughtCount}\n`);
sequenceData.thoughts.forEach((thought, index) => {
console.log(`${index + 1}. ${thought.thought}`);
});
// Get the branch
console.log('\n=== Alternative Branch ===\n');
const branch = await client.callTool({
name: 'get_thought_branch',
arguments: {
branchId: 'alternative-architecture',
},
});
const branchData = JSON.parse(branch.content[0].text);
console.log(`Branch: ${branchData.branchId}`);
console.log(`Thoughts in branch: ${branchData.thoughtCount}\n`);
branchData.thoughts.forEach((thought, index) => {
console.log(`${index + 1}. ${thought.thought}`);
});
// Get session summary
console.log('\n=== Session Summary ===\n');
const summary = await client.callTool({
name: 'get_session_summary',
arguments: {},
});
console.log(JSON.parse(summary.content[0].text));
// Close the connection
await client.close();
console.log('\nDisconnected from server');
}
main().catch(console.error);