MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / forward_to_nlweb

Function forward_to_nlweb

AskAgent/python/chatbot_interface.py:23–59  ·  view source on GitHub ↗

Forward a request to the NLWeb MCP endpoint

(function_name: str, arguments: dict[str, Any], server_url: str, endpoint: str)

Source from the content-addressed store, hash-verified

21DEFAULT_ENDPOINT = "/mcp"
22
23async def forward_to_nlweb(function_name: str, arguments: dict[str, Any], server_url: str, endpoint: str) -> dict[str, Any]:
24 """Forward a request to the NLWeb MCP endpoint"""
25 nlweb_mcp_url = f"{server_url}{endpoint}"
26 try:
27 # Format the request in MCP format
28 payload = {
29 "function_call": {
30 "name": function_name,
31 "arguments": json.dumps(arguments)
32 }
33 }
34
35 # Print some debug info to stderr (won't interfere with stdio protocol)
36 print(f"Forwarding to {nlweb_mcp_url}: {function_name}", file=sys.stderr)
37
38 async with httpx.AsyncClient() as client:
39 response = await client.post(
40 nlweb_mcp_url,
41 json=payload,
42 headers={"Content-Type": "application/json"},
43 timeout=30
44 )
45
46 if response.status_code != 200:
47 print(f"Error from server: {response.status_code} - {response.text}", file=sys.stderr)
48 return {
49 "error": f"Server error: {response.status_code} - {response.text}"
50 }
51
52 result = response.json()
53 return result
54
55 except Exception as e:
56 print(f"Request failed: {e!s}", file=sys.stderr)
57 return {
58 "error": f"Request failed: {e!s}"
59 }
60
61async def serve(server_url: str = DEFAULT_SERVER_URL, endpoint: str = DEFAULT_ENDPOINT) -> None:
62 """

Callers 4

list_toolsFunction · 0.85
list_promptsFunction · 0.85
call_toolFunction · 0.85
get_promptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected