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
174 lines • 6.53 kB
JavaScript
import { SystemPromptService } from "../services/systemprompt-service.js";
import { sendOperationNotification, sendPromptChangedNotification, sendResourceChangedNotification } from "./notifications.js";
/**
* Handles creating a systemprompt prompt
* @param result The LLM result
* @returns The tool response
*/
export async function handleCreatePromptCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const promptRequest = JSON.parse(result.content.text);
const request = {
instruction: {
static: promptRequest.instruction.static,
state: "{{conversation.history}}",
dynamic: "{{message}}",
},
input: {
name: "DefaultInputSchema",
description: "DefaultInputSchema Description",
type: ["message"],
schema: {
type: "object",
properties: {
$schema: {
type: "string",
description: "The JSON Schema version",
default: "http://json-schema.org/draft-07/schema#",
},
type: {
type: "string",
enum: ["object"],
},
properties: {
name: {
type: "string",
},
},
},
required: ["name"],
additionalProperties: {
type: "boolean",
},
},
},
output: {
name: "DefaultOutputSchema",
description: "DefaultOutputSchema Description",
type: ["message"],
schema: {
type: "object",
properties: {
$schema: {
type: "string",
description: "The JSON Schema version",
default: "http://json-schema.org/draft-07/schema#",
},
type: {
type: "string",
enum: ["object"],
},
properties: {
name: {
type: "string",
},
},
},
required: ["name"],
additionalProperties: {
type: "boolean",
},
},
},
metadata: {
title: promptRequest.metadata.title,
description: promptRequest.metadata.description,
tag: promptRequest.metadata.tag,
log_message: promptRequest.metadata.log_message,
},
};
const service = SystemPromptService.getInstance();
const prompt = await service.createPrompt(request);
const message = `Successfully created ${prompt.metadata.title} with id: ${prompt.id}`;
await sendOperationNotification("create_prompt", message);
await sendPromptChangedNotification();
return message;
}
/**
* Handles editing a systemprompt prompt
* @param result The LLM result
* @returns The tool response
*/
export async function handleEditPromptCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const { uuid, ...updateData } = JSON.parse(result.content.text);
const service = SystemPromptService.getInstance();
const prompt = await service.editPrompt(uuid, updateData);
const message = `Successfully edited ${prompt.metadata.title} with id: ${prompt.id}`;
await sendOperationNotification("edit_prompt", message);
await sendPromptChangedNotification();
return message;
}
/**
* Handles creating a systemprompt block
* @param result The LLM result
* @returns The tool response
*/
export async function handleCreateBlockCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const blockRequest = JSON.parse(result.content.text);
const service = SystemPromptService.getInstance();
const block = await service.createBlock(blockRequest);
const message = `Successfully created ${block.metadata.title} with id: ${block.id}`;
await sendOperationNotification("create_block", message);
await sendResourceChangedNotification();
return message;
}
/**
* Handles editing a systemprompt block
* @param result The LLM result
* @returns The tool response
*/
export async function handleEditBlockCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const { uuid, ...updateData } = JSON.parse(result.content.text);
const service = SystemPromptService.getInstance();
const block = await service.editBlock(uuid, updateData);
const message = `Successfully edited ${block.metadata.title} with id: ${block.id}`;
await sendOperationNotification("edit_block", message);
await sendResourceChangedNotification();
return message;
}
/**
* Handles creating a systemprompt agent
* @param result The LLM result
* @returns The tool response
*/
export async function handleCreateAgentCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const agentRequest = JSON.parse(result.content.text);
const service = SystemPromptService.getInstance();
const agent = await service.createAgent(agentRequest);
const message = `Successfully created ${agent.metadata.title} with id: ${agent.id}`;
await sendOperationNotification("create_agent", message);
await sendResourceChangedNotification();
return message;
}
/**
* Handles editing a systemprompt agent
* @param result The LLM result
* @returns The tool response
*/
export async function handleEditAgentCallback(result) {
if (result.content.type !== "text") {
throw new Error("Expected text content");
}
const { uuid, ...updateData } = JSON.parse(result.content.text);
const service = SystemPromptService.getInstance();
const agent = await service.editAgent(uuid, updateData);
const message = `Successfully edited ${agent.metadata.title} with id: ${agent.id}`;
await sendOperationNotification("edit_agent", message);
await sendResourceChangedNotification();
return message;
}
//# sourceMappingURL=callbacks.js.map