| 1 | import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 2 | |
| 3 | import { SlashCommandWithSource } from "../../index.js"; |
| 4 | |
| 5 | export function constructMcpSlashCommand( |
| 6 | client: Client, |
| 7 | name: string, |
| 8 | description?: string, |
| 9 | args?: string[], |
| 10 | ): SlashCommandWithSource { |
| 11 | return { |
| 12 | name, |
| 13 | description: description ?? "MCP Prompt", |
| 14 | source: "mcp-prompt", |
| 15 | params: {}, |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | export function stringifyMcpPrompt( |
| 20 | prompt: Awaited<ReturnType<typeof Client.prototype.getPrompt>>, |
| 21 | ): string { |
| 22 | const { messages } = prompt; |
| 23 | let stringified = ""; |
| 24 | for (const message of messages) { |
| 25 | if (message.content.type === "text") { |
| 26 | stringified += `<${message.content.role}/>\n${message.content.text}\n<${message.content.role}/>`; |
| 27 | } else { |
| 28 | console.warn( |
| 29 | `MCP Prompt conversion warning: ${message.content.type} content is not yet supported, message skipped`, |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 | return stringified; |
| 34 | } |