Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
7.1 kB · 278 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279// MCP Server for aesthetic.computer// Exposes tools, resources, and prompts for publishing and exploring pieces
import { Server } from "@modelcontextprotocol/sdk/server/index.js";import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema,} from "@modelcontextprotocol/sdk/types.js";
// Import toolsimport { publishPieceTool, publishPiece } from "./tools/publish-piece.js";import { publishKidLispTool, publishKidLisp } from "./tools/publish-kidlisp.js";import { publishClockTool, publishClock } from "./tools/publish-clock.js";import { getAPIInfoTool, getAPIInfo } from "./tools/get-api-info.js";import { previewKidLispTool, previewKidLisp,} from "./tools/preview-kidlisp.js";
// Import resourcesimport { pieceTemplateResource, getPieceTemplate,} from "./resources/piece-template.js";import { kidlispReferenceResource, getKidLispReference,} from "./resources/kidlisp-reference.js";import { pieceExamplesResource, getPieceExamples,} from "./resources/piece-examples.js";
// Import promptsimport { createPiecePrompt, getCreatePiecePrompt,} from "./prompts/create-piece.js";import { createKidLispPrompt, getCreateKidLispPrompt,} from "./prompts/create-kidlisp.js";
export class AestheticComputerServer { private server: Server; private token?: string;
constructor(token?: string) { this.token = token; this.server = new Server( { name: "aesthetic-computer", version: "1.1.0", }, { capabilities: { tools: {}, resources: {}, prompts: {}, }, } );
this.setupHandlers(); }
private setupHandlers() { // List available tools this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ publishPieceTool, publishKidLispTool, publishClockTool, getAPIInfoTool, previewKidLispTool, ], }));
// Handle tool calls this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params;
try { switch (name) { case "publish_piece": return { content: [ { type: "text", text: JSON.stringify( await publishPiece( args as { source: string; name?: string }, this.token ), null, 2 ), }, ], };
case "publish_kidlisp": return { content: [ { type: "text", text: JSON.stringify( await publishKidLisp(args as { source: string }, this.token), null, 2 ), }, ], };
case "publish_clock": return { content: [ { type: "text", text: JSON.stringify( await publishClock(args as { source: string }, this.token), null, 2 ), }, ], };
case "get_api_info": return { content: [ { type: "text", text: JSON.stringify(await getAPIInfo(), null, 2), }, ], };
case "preview_kidlisp": return { content: [ { type: "text", text: JSON.stringify( await previewKidLisp(args as { source: string }), null, 2 ), }, ], };
default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } });
// List available resources this.server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources: [ pieceTemplateResource, kidlispReferenceResource, pieceExamplesResource, ], }));
// Read resource content this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => { const { uri } = request.params;
switch (uri) { case "aesthetic-computer://piece-template": return { contents: [ { uri, mimeType: "text/javascript", text: getPieceTemplate(), }, ], };
case "aesthetic-computer://kidlisp-reference": return { contents: [ { uri, mimeType: "text/markdown", text: getKidLispReference(), }, ], };
case "aesthetic-computer://piece-examples": return { contents: [ { uri, mimeType: "text/markdown", text: getPieceExamples(), }, ], };
default: throw new Error(`Unknown resource: ${uri}`); } });
// List available prompts this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: [createPiecePrompt, createKidLispPrompt], }));
// Get prompt content this.server.setRequestHandler(GetPromptRequestSchema, async (request) => { const { name, arguments: args } = request.params;
switch (name) { case "create-piece": return { messages: [ { role: "user", content: { type: "text", text: getCreatePiecePrompt( args as { name: string; description: string } ), }, }, ], };
case "create-kidlisp": return { messages: [ { role: "user", content: { type: "text", text: getCreateKidLispPrompt( args as { description: string } ), }, }, ], };
default: throw new Error(`Unknown prompt: ${name}`); } }); }
async run() { const transport = new StdioServerTransport(); await this.server.connect(transport); console.error("Aesthetic Computer MCP server running on stdio"); }}