index.ts•1.35 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { registerPrompts } from "./prompts/index.js";
import { registerTools } from "./tools/index.js";
// Initialize the MCP Server instance
export const server = new McpServer({
name: "color-scheme-generator", // Unique name for this server
version: "0.0.1", // Server version
// Declare the types of capabilities the server will offer
capabilities: {
prompts: {}, // Will be populated by registerPrompts
tools: {}, // Will be populated by registerTools
},
});
// Load and register all defined prompts and tools
registerPrompts();
registerTools();
// Main entry point for the server application
async function main(): Promise<void> {
// Use StdioServerTransport to communicate over standard input/output
// This is common for MCP servers launched as child processes by clients.
const transport = new StdioServerTransport();
// Connect the server logic to the transport layer
await server.connect(transport);
console.log("Server started and connected successfully===============");
}
// Start the server and handle potential errors
main().catch((error: Error) => {
console.error("Server startup failed:", error); // Log errors to stderr
process.exit(1);
});