Forward tool calls to NLWeb
(name: str, arguments: dict)
| 175 | |
| 176 | @server.call_tool() |
| 177 | async def call_tool(name: str, arguments: dict) -> list[TextContent]: |
| 178 | """Forward tool calls to NLWeb""" |
| 179 | result = await forward_to_nlweb(name, arguments, server_url, endpoint) |
| 180 | |
| 181 | if "error" in result: |
| 182 | return [TextContent(type="text", text=f"Error: {result['error']}")] |
| 183 | |
| 184 | # Extract response from the result |
| 185 | try: |
| 186 | response_data = result.get("response", {}) |
| 187 | # Convert to string if it's not already |
| 188 | if isinstance(response_data, (dict, list)): |
| 189 | response_text = json.dumps(response_data, indent=2) |
| 190 | else: |
| 191 | response_text = str(response_data) |
| 192 | |
| 193 | return [TextContent(type="text", text=response_text)] |
| 194 | except Exception as e: |
| 195 | print(f"Error processing tool response: {e!s}", file=sys.stderr) |
| 196 | return [TextContent(type="text", text=f"Error processing response: {e!s}")] |
| 197 | |
| 198 | @server.get_prompt() |
| 199 | async def get_prompt(name: str, arguments: dict | None) -> GetPromptResult: |
nothing calls this directly
no test coverage detected