Forward list_prompts request to NLWeb
()
| 123 | |
| 124 | @server.list_prompts() |
| 125 | async def list_prompts() -> list[Prompt]: |
| 126 | """Forward list_prompts request to NLWeb""" |
| 127 | result = await forward_to_nlweb("list_prompts", {}, server_url, endpoint) |
| 128 | |
| 129 | if "error" in result: |
| 130 | # Fallback to default if server is unavailable |
| 131 | return [ |
| 132 | Prompt( |
| 133 | name="ask_nlw", |
| 134 | description="Connects with the NLWeb server to answer questions", |
| 135 | arguments=[ |
| 136 | PromptArgument( |
| 137 | name="query", |
| 138 | description="query string in english", |
| 139 | required=True |
| 140 | ) |
| 141 | ] |
| 142 | ) |
| 143 | ] |
| 144 | |
| 145 | # Extract prompts from the response |
| 146 | try: |
| 147 | prompts = result.get("response", {}).get("prompts", []) |
| 148 | return [Prompt( |
| 149 | name=prompt["id"], |
| 150 | description=prompt["description"], |
| 151 | arguments=[ |
| 152 | PromptArgument( |
| 153 | name="query", |
| 154 | description="query string in english", |
| 155 | required=True |
| 156 | ) |
| 157 | ] |
| 158 | ) for prompt in prompts] |
| 159 | except (KeyError, TypeError) as e: |
| 160 | print(f"Error processing prompts: {e!s}", file=sys.stderr) |
| 161 | # Fallback to default |
| 162 | return [ |
| 163 | Prompt( |
| 164 | name="ask_nlw", |
| 165 | description="Connects with the NLWeb server to answer questions", |
| 166 | arguments=[ |
| 167 | PromptArgument( |
| 168 | name="query", |
| 169 | description="query string in english", |
| 170 | required=True |
| 171 | ) |
| 172 | ] |
| 173 | ) |
| 174 | ] |
| 175 | |
| 176 | @server.call_tool() |
| 177 | async def call_tool(name: str, arguments: dict) -> list[TextContent]: |
nothing calls this directly
no test coverage detected