import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import * as services from "./index.js";
/**
* Register all resources with the MCP server
* @param server The MCP server instance
*/
export function registerResources(server: McpServer) {
// Diagram resource
server.resource(
"mermaid_resource",
"diagram://{id}",
async (uri: URL) => {
const id = uri.pathname.split('/').pop();
if (!id) {
throw new Error(`Invalid diagram ID`);
}
const diagramContent = services.getDiagram(id);
if (!diagramContent) {
throw new Error(`Diagram with ID '${id}' not found`);
}
return {
contents: [{
uri: uri.toString(),
text: diagramContent
}]
};
}
);
// Add resource to list all available diagrams
server.resource(
"application/json",
"diagram://list",
async () => {
const diagrams = services.listDiagrams();
return {
contents: [{
uri: "diagram://list",
text: JSON.stringify(diagrams, null, 2)
}]
};
}
);
// Create and connect to storage
storageAdapter = await createStorageAdapter(DEFAULT_CONFIG);
await storageAdapter.connect();
// Initialize default prompts
await initializeDefaultPrompts();
// Create MCP server
const server = new Server();
// Register prompt resources
server.resource('prompts', {
get: async ({ id }) => {
const prompt = await storageAdapter.getPrompt(id);
if (!prompt) {
throw new Error(`Prompt not found: ${id}`);
}
return prompt;
},
list: async () => {
return storageAdapter.listPrompts({});
}
});
server.resource('templates', {
list: async () => {
return storageAdapter.listPrompts({ isTemplate: true });
}
});
}