UNPKG

systemprompt-mcp-core

Version:

A specialized Model Context Protocol (MCP) server that integrates with systemprompt.io to provide powerful prompt management capabilities. This server enables seamless creation, management, and versioning of system prompts and agents through MCP. It works

46 lines 2.13 kB
import { SystemPromptService } from "../services/systemprompt-service.js"; import { mapBlockToReadResourceResult, mapBlocksToListResourcesResult, mapAgentsToListResourcesResult, mapAgentToReadResourceResult } from "../utils/mcp-mappers.js"; export async function handleListResources(request) { try { const service = SystemPromptService.getInstance(); const blocks = await service.listBlocks(); const agents = await service.listAgents(); const blockResources = mapBlocksToListResourcesResult(blocks); const agentResources = mapAgentsToListResourcesResult(agents); return { _meta: {}, resources: [...blockResources.resources, ...agentResources.resources], }; } catch (error) { console.error("Failed to fetch resources:", error); throw new Error(`Failed to fetch resources from systemprompt.io: ${error.message || "Unknown error"}`); } } export async function handleResourceCall(request) { try { const service = SystemPromptService.getInstance(); const { uri } = request.params; const blockMatch = uri.match(/^resource:\/\/\/block\/(.+)$/); const agentMatch = uri.match(/^resource:\/\/\/agent\/(.+)$/); if (!blockMatch && !agentMatch) { throw new Error("Invalid resource URI format - expected resource:///block/{id} or resource:///agent/{id}"); } if (blockMatch) { const blockId = blockMatch[1]; const block = await service.getBlock(blockId); return mapBlockToReadResourceResult(block); } else if (agentMatch) { const agentId = agentMatch[1]; const agent = await service.getAgent(agentId); return mapAgentToReadResourceResult(agent); } throw new Error("Failed to process resource request"); } catch (error) { console.error("Failed to fetch resource:", error); throw new Error(`Failed to fetch resource from systemprompt.io: ${error.message || "Unknown error"}`); } } //# sourceMappingURL=resource-handlers.js.map