onerios-mcp-server
Version:
OneriosMCP server providing memory, backlog management, file operations, and utility functions for enhanced AI assistant capabilities
166 lines (165 loc) • 7.26 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MCPServer = void 0;
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
// Import our function modules
const file_operations_js_1 = require("./modules/file-operations.js");
const text_processing_js_1 = require("./modules/text-processing.js");
const data_analysis_js_1 = require("./modules/data-analysis.js");
const web_utils_js_1 = require("./modules/web-utils.js");
const memory = __importStar(require("./modules/memory.js"));
const backlog_adapter_js_1 = require("./modules/backlog-adapter.js");
const github_auth_handlers_js_1 = require("./modules/github-auth-handlers.js");
/**
* MCP Server for VS Code Copilot Integration
*
* This server provides various utility functions organized into modules:
* - File Operations: Read, write, search files and directories
* - Text Processing: Text analysis, formatting, and manipulation
* - Data Analysis: JSON processing, CSV handling, data transformation
* - Web Utils: URL validation, HTTP requests, web scraping utilities
* - Memory: Knowledge graph-based persistent memory with entities and relations
* - Backlog Manager: Issue and task management with project backlog tracking
* - GitHub Integration: GitHub Projects API authentication and integration tools
*/
class MCPServer {
constructor() {
this.server = new index_js_1.Server({
name: 'copilot-mcp-server',
version: '1.0.0',
}, {
capabilities: {
tools: {},
},
});
this.setupHandlers();
}
setupHandlers() {
// List all available tools
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
return {
tools: [
...file_operations_js_1.fileOperations.getTools(),
...text_processing_js_1.textProcessing.getTools(),
...data_analysis_js_1.dataAnalysis.getTools(),
...web_utils_js_1.webUtils.getTools(),
...memory.getTools(),
...backlog_adapter_js_1.backlogManager.getTools(),
...github_auth_handlers_js_1.githubAuthTools,
],
};
});
// Handle tool execution
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
// Route to appropriate module based on tool name
if (file_operations_js_1.fileOperations.hasHandler(name)) {
const result = await file_operations_js_1.fileOperations.handleTool(name, args);
return {
content: result.content,
};
}
if (text_processing_js_1.textProcessing.hasHandler(name)) {
const result = await text_processing_js_1.textProcessing.handleTool(name, args);
return {
content: result.content,
};
}
if (data_analysis_js_1.dataAnalysis.hasHandler(name)) {
const result = await data_analysis_js_1.dataAnalysis.handleTool(name, args);
return {
content: result.content,
};
}
if (web_utils_js_1.webUtils.hasHandler(name)) {
const result = await web_utils_js_1.webUtils.handleTool(name, args);
return {
content: result.content,
};
}
if (backlog_adapter_js_1.backlogManager.hasHandler(name)) {
const result = await backlog_adapter_js_1.backlogManager.handleTool(name, args);
return {
content: result.content,
};
}
// Check memory module (uses different pattern)
if (name.startsWith('memory_')) {
const result = await memory.handleTool(name, args);
return result;
}
// Check GitHub authentication tools
if (name.startsWith('github_')) {
const handler = github_auth_handlers_js_1.githubAuthHandlers[name];
if (handler) {
const result = await handler(args);
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2)
}
]
};
}
}
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Error executing tool ${name}: ${errorMessage}`);
}
});
}
async run() {
const transport = new stdio_js_1.StdioServerTransport();
await this.server.connect(transport);
console.error('MCP Server running on stdio');
}
}
exports.MCPServer = MCPServer;
// Start the server
if (require.main === module) {
const server = new MCPServer();
server.run().catch((error) => {
console.error('Failed to start server:', error);
process.exit(1);
});
}