NLWeb Network
Network interfaces and server for NLWeb - provides HTTP, MCP, and A2A protocol adapters.
Overview
nlweb-network provides transport layer adapters that convert protocol-specific requests into a common format for NLWeb handlers, and convert NLWeb outputs back into the appropriate protocol format.
Architecture
┌──────────────────────────────────────────────┐
│ Protocol Adapters │
│ (HTTP SSE, HTTP JSON, MCP SSE, MCP HTTP) │
└──────────────────┬───────────────────────────┘
│
↓
┌─────────────────┐
│ NLWeb Handlers │
│ (Core Package) │
└─────────────────┘
Supported Protocols
HTTP Interfaces
HTTP with Server-Sent Events (Default)
- Endpoint:
/ask(GET/POST) - Parameter:
streaming=true(default) - Use case: Real-time streaming of results as they're generated
curl "http://localhost:8080/ask?query=best+pasta+recipe"
HTTP with JSON Response
- Endpoint:
/ask(GET/POST) - Parameter:
streaming=false - Use case: Get complete results in single JSON response
curl "http://localhost:8080/ask?query=best+pasta+recipe&streaming=false"
MCP (Model Context Protocol) Interfaces
MCP over HTTP (StreamableHTTP)
- Endpoint:
/mcp(POST) - Format: JSON-RPC 2.0
- Use case: Standard MCP integration for tools/agents
# Test with MCP Inspector
npx @modelcontextprotocol/inspector http://localhost:8080/mcp
MCP over Server-Sent Events
- Endpoint:
/mcp-sse(GET/POST) - Format: JSON-RPC 2.0 over SSE
- Use case: Streaming MCP responses in real-time
A2A (Agent-to-Agent) Interfaces
(Coming soon)
Installation
# Install from PyPI (when published)
pip install nlweb-network
# Or install from source
pip install -e packages/network
Usage
Starting the Server
from nlweb_network.server import main
# Start server with default configuration
main()
Or use the command-line entry point:
nlweb-server
Using Interface Adapters
You can use the interface adapters directly in your own applications:
from aiohttp import web
from nlweb_network.interfaces import HTTPJSONInterface, HTTPSSEInterface
from nlweb_core.handler import NLWebHandler
# For non-streaming JSON responses
async def my_handler(request):
interface = HTTPJSONInterface()
return await interface.handle_request(request, NLWebHandler)
# For streaming SSE responses
async def my_streaming_handler(request):
interface = HTTPSSEInterface()
return await interface.handle_request(request, NLWebHandler)
Interface Adapters
All interface adapters inherit from BaseInterface and implement:
parse_request()- Extract query parameters from protocol-specific requestsend_response()- Send data in protocol-specific formatfinalize_response()- Close/finalize the response streamhandle_request()- Complete request/response cycle
Available Interfaces
| Interface | Class | Protocol | Streaming |
|---|---|---|---|
| HTTP JSON | HTTPJSONInterface |
HTTP | No |
| HTTP SSE | HTTPSSEInterface |
HTTP + SSE | Yes |
| MCP StreamableHTTP | MCPStreamableInterface |
JSON-RPC 2.0 | No |
| MCP SSE | MCPSSEInterface |
JSON-RPC 2.0 + SSE | Yes |
Configuration
The server uses configuration from nlweb-core:
# config.yaml
server:
host: localhost
port: 8080
enable_cors: true
Endpoints
/ask - HTTP Query Endpoint
GET/POST - Natural language query with NLWeb RAG pipeline
Parameters:
query(required) - Natural language querysite(optional) - Filter by site (default: "all")num_results(optional) - Number of results (default: 50)streaming(optional) - Enable SSE streaming (default: true)
Examples:
# Streaming (SSE)
curl "http://localhost:8080/ask?query=spicy+snacks&site=seriouseats"
# Non-streaming (JSON)
curl "http://localhost:8080/ask?query=spicy+snacks&streaming=false"
# POST with JSON body
curl -X POST http://localhost:8080/ask \
-H 'Content-Type: application/json' \
-d '{"query": "spicy snacks", "streaming": false}'
/mcp - MCP Protocol Endpoint
POST - JSON-RPC 2.0 requests for MCP protocol
Methods:
initialize- Protocol handshaketools/list- List available toolstools/call- Execute tool (routes to NLWeb handlers)
Example:
curl -X POST http://localhost:8080/mcp \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "ask",
"arguments": {"query": "best pasta recipe"}
}
}'
/mcp-sse - MCP with SSE Streaming
GET/POST - MCP protocol with Server-Sent Events
Same as /mcp but streams results via SSE for tools/call.
/health - Health Check
GET - Simple health check
curl http://localhost:8080/health
# {"status": "ok"}
Dependencies
nlweb-core>=0.5.0- Core NLWeb handlers and business logicaiohttp>=3.8.0- Async HTTP serveraiohttp-cors>=0.7.0- CORS support
Development
# Install in editable mode with dev dependencies
pip install -e "packages/network[dev]"
# Run tests
pytest packages/network/tests
License
MIT License - Copyright (c) 2025 Microsoft Corporation
Metadata
Release files for nlweb-network 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nlweb_network-0.7.0.tar.gz | 19.6 kB | Without provenance | Details for nlweb_network-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nlweb_network-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for nlweb_network-0.7.0-py3-none-any.whl |
Total release size: 44.9 kB
Release files / nlweb_network-0.7.0.tar.gz
| Download URL | nlweb_network-0.7.0.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a1acb495e937f2b3c385c3ed56af6f4b07dc070f5b3e6d9d6f00b723ddfc194f
|
|
BLAKE2b-256 checksum How to use checksums |
183e5b9b52b855b59e9d1ec55378cf65d4575ed8a832adc3c998049de4128c07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / nlweb_network-0.7.0-py3-none-any.whl
| Download URL | nlweb_network-0.7.0-py3-none-any.whl |
|---|---|
| Size | 25.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f00fda36a0dffa5f474963c4fd8a33138c98cf7049787a8df383b80e3eab41e0
|
|
BLAKE2b-256 checksum How to use checksums |
57120cfb6b6a0c5ffff18fc16ef1dc4ce21039982aa60f3164464814a6c3ee6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for nlweb-network 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.