Forward get_prompt to NLWeb
(name: str, arguments: dict | None)
| 197 | |
| 198 | @server.get_prompt() |
| 199 | async def get_prompt(name: str, arguments: dict | None) -> GetPromptResult: |
| 200 | """Forward get_prompt to NLWeb""" |
| 201 | if not arguments: |
| 202 | arguments = {} |
| 203 | |
| 204 | # Add the prompt name as prompt_id if not present |
| 205 | if "prompt_id" not in arguments: |
| 206 | arguments["prompt_id"] = name |
| 207 | |
| 208 | result = await forward_to_nlweb("get_prompt", arguments, server_url, endpoint) |
| 209 | |
| 210 | if "error" in result: |
| 211 | return GetPromptResult( |
| 212 | description=f"Failed to get prompt {arguments.get('prompt_id', name)}", |
| 213 | messages=[ |
| 214 | PromptMessage( |
| 215 | role="user", |
| 216 | content=TextContent(type="text", text=f"Error: {result['error']}") |
| 217 | ) |
| 218 | ] |
| 219 | ) |
| 220 | |
| 221 | # Extract prompt from the response |
| 222 | try: |
| 223 | prompt_data = result.get("response", {}) |
| 224 | prompt_text = prompt_data.get("prompt_text", f"Prompt for {name}") |
| 225 | |
| 226 | return GetPromptResult( |
| 227 | description=f"Prompt: {prompt_data.get('name', name)}", |
| 228 | messages=[ |
| 229 | PromptMessage( |
| 230 | role="user", |
| 231 | content=TextContent(type="text", text=prompt_text) |
| 232 | ) |
| 233 | ] |
| 234 | ) |
| 235 | except Exception as e: |
| 236 | print(f"Error processing prompt: {e!s}", file=sys.stderr) |
| 237 | return GetPromptResult( |
| 238 | description=f"Error getting prompt {name}", |
| 239 | messages=[ |
| 240 | PromptMessage( |
| 241 | role="user", |
| 242 | content=TextContent(type="text", text=f"Error: {e!s}") |
| 243 | ) |
| 244 | ] |
| 245 | ) |
| 246 | |
| 247 | # Run the server |
| 248 | options = server.create_initialization_options() |
nothing calls this directly
no test coverage detected