@whyuds/coding-converse
Version:
An MCP server that enables interactive conversations between AI code editors and users for collaborative problem-solving
157 lines • 6.16 kB
JavaScript
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
import { ConversationManager } from './conversation-manager.js';
import { TerminalInterface } from './terminal-interface.js';
class CodingConverseServer {
constructor() {
this.server = new Server({
name: 'coding-converse',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
this.conversationManager = new ConversationManager();
this.terminalInterface = new TerminalInterface();
this.setupHandlers();
}
setupHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'ask_user',
description: 'Ask the user a question and wait for their response. Use this when you need clarification, suggestions, or user input to proceed with code generation.',
inputSchema: {
type: 'object',
properties: {
question: {
type: 'string',
description: 'The question to ask the user'
},
context: {
type: 'string',
description: 'Additional context about the current situation or problem'
},
options: {
type: 'array',
items: { type: 'string' },
description: 'Optional: Suggested response options for the user'
}
},
required: ['question']
}
},
{
name: 'start_conversation',
description: 'Start a new conversation session with the user',
inputSchema: {
type: 'object',
properties: {
topic: {
type: 'string',
description: 'The topic or problem to discuss'
}
},
required: ['topic']
}
},
{
name: 'end_conversation',
description: 'End the current conversation session',
inputSchema: {
type: 'object',
properties: {
summary: {
type: 'string',
description: 'Summary of the conversation and decisions made'
}
},
required: ['summary']
}
}
]
};
});
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
switch (name) {
case 'ask_user':
return await this.handleAskUser(args);
case 'start_conversation':
return await this.handleStartConversation(args);
case 'end_conversation':
return await this.handleEndConversation(args);
default:
throw new Error(`Unknown tool: ${name}`);
}
}
catch (error) {
return {
content: [
{
type: 'text',
text: `Error: ${error instanceof Error ? error.message : String(error)}`
}
],
isError: true
};
}
});
}
async handleAskUser(args) {
const { question, context, options } = args;
const response = await this.terminalInterface.askUser({
question,
context,
options
});
this.conversationManager.addExchange(question, response);
return {
content: [
{
type: 'text',
text: `User response: ${response}`
}
]
};
}
async handleStartConversation(args) {
const { topic } = args;
this.conversationManager.startNewConversation(topic);
await this.terminalInterface.displayConversationStart(topic);
return {
content: [
{
type: 'text',
text: `Conversation started for topic: ${topic}`
}
]
};
}
async handleEndConversation(args) {
const { summary } = args;
this.conversationManager.endConversation(summary);
await this.terminalInterface.displayConversationEnd(summary);
return {
content: [
{
type: 'text',
text: `Conversation ended. Summary: ${summary}`
}
]
};
}
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error('CodingConverse MCP server running on stdio');
}
}
const server = new CodingConverseServer();
server.run().catch(console.error);
//# sourceMappingURL=index.js.map