Files
cokaremote/src/mcp-server.ts
T
2026-08-19 22:52:46 +09:00

54 lines
1.9 KiB
TypeScript

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { AppConfig } from "./config.js";
import { registerExecTools } from "./exec-tools.js";
import { FileService } from "./file-service.js";
import { registerFileTools } from "./file-tools.js";
import { ProcessManager } from "./process-manager.js";
export interface McpServices {
processManager: ProcessManager;
fileService: FileService;
}
export function createServices(config: AppConfig): McpServices {
return {
processManager: new ProcessManager({
maxRetainedOutputBytes: config.maxRetainedProcessOutputBytes,
processRetentionMs: config.processRetentionMs,
maxProcesses: config.maxProcesses,
defaultMaxOutputBytes: config.maxOutputBytes,
}),
fileService: new FileService({
defaultCwd: config.defaultCwd,
maxChunkBytes: config.maxFileChunkBytes,
maxEditFileBytes: config.maxEditFileBytes,
maxOutputBytes: config.maxOutputBytes,
}),
};
}
export function createMcpServer(config: AppConfig, services: McpServices): McpServer {
const server = new McpServer(
{
name: "cokacremote",
version: "0.1.0",
...(config.publicUrl ? { websiteUrl: config.publicUrl } : {}),
},
{
instructions:
"This server is an unrestricted remote development environment. Tools operate directly on the host with the MCP service process's full OS permissions. Use exec_command for shell, build, test, package, Git, service, and log workflows; run_script for complete Bash, Node.js, or Python scripts; and the file tools for direct file operations. Poll long-running commands with read_process or write_stdin.",
capabilities: { logging: {} },
},
);
registerExecTools(
server,
config,
services.processManager,
services.fileService,
);
registerFileTools(server, config, services.fileService);
return server;
}