* Retrieves a prompt from an MCP server by its URI and processes its content. * * This method parses the provided URI to extract the connection ID and prompt name, * fetches the prompt from the corresponding MCP server, and converts any structured * content into a standardized format.
(options: MCPPromptsManager.GetOptions)
| 166 | * @param options - The options for retrieving a prompt, including the prompt URI and arguments |
| 167 | */ |
| 168 | async get(options: MCPPromptsManager.GetOptions) { |
| 169 | const promptURI = this.#parsePromptURI(options.uri); |
| 170 | |
| 171 | if (!promptURI) { |
| 172 | throw new Error("Invalid prompt uri format."); |
| 173 | } |
| 174 | |
| 175 | const connection = this.#connectionsManager.getConnectedOrThrow(promptURI.connectionId); |
| 176 | |
| 177 | if (!this.#loadedPrompts.find((prompt) => prompt.uri === options.uri)) { |
| 178 | throw new Error("Prompt not found."); |
| 179 | } |
| 180 | |
| 181 | return connection.client.getPrompt({ name: promptURI.name, arguments: options.arguments }).then((result) => { |
| 182 | return { |
| 183 | description: result.description, |
| 184 | messages: result.messages.map((message) => { |
| 185 | let content = this.#contentConverter.convert(message.content, promptURI.connectionId); |
| 186 | |
| 187 | // Some models or providers may throw errors when receiving messages with empty content |
| 188 | if (content.type === "text" && !content.text.trim()) { |
| 189 | content = { |
| 190 | type: "text", |
| 191 | text: "<tip>The previous message had empty content.</tip>", |
| 192 | }; |
| 193 | } |
| 194 | |
| 195 | return { |
| 196 | role: message.role, |
| 197 | content, |
| 198 | }; |
| 199 | }), |
| 200 | }; |
| 201 | }); |
| 202 | } |
| 203 | |
| 204 | async legacyList() { |
| 205 | const bundles = Array.from(this.state.collections.entries()).map(([id, collection]) => { |
no test coverage detected