/nlweb-protocol:nlweb-ask-endpointfrom nlweb-protocol
Implements and consumes the NLWeb /ask REST endpoint covering GET/POST request shapes, SSE streaming responses, modes (list/summarize/generate), in-stream message_type headers, error envelopes, and client-side parsing. Useful when building an NLWeb server route, calling /ask from a custom agent, or debugging /ask responses.
Ships in nlweb-protocol. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Fetch live spec:
/ask contract — request params, response shape, and streaming format.query.text, prefer.mode, prefer.streaming, meta.version) — this is newer than the GET-only legacy contract.webserver/routes/api.py in the live repo to confirm exact param names.| Route | Method | Purpose |
|---|---|---|
/ask | GET, POST | Main NL query |
/who | GET | Site relevance for a query (federated) |
/sites | GET | List configured sites |
/config | GET | Public config (safe subset) |
Verify exact names against the live routes/api.py. Stable subset:
| Param | Type | Required | Default | Notes |
|---|---|---|---|---|
query | string | yes | — | NL question |
site | string | no | all | Backend partition; in MCP can be array |
prev | string | no | — | Comma-separated previous queries (conversation context) |
decontextualized_query | string | no | — | Pre-resolved query; skips server-side decontextualization |
streaming | bool | no | true | "0" / "false" / "False" disables |
query_id | string | no | auto | Echoed in response |
mode | enum | no | list | list | summarize | generate |
scorer | string | no | default | e.g., nlwebscorer for the neural reranker |
itemType | string | no | — | Schema.org type hint (skip type detection) |
response_format | string | no | — | v0.55 structured-body field |
The newer body format groups fields:
{
"query": { "text": "your question" },
"context": { "prev": ["previous q1", "previous q2"] },
"prefer": {
"mode": "list",
"streaming": true,
"response_format": "schema"
},
"meta": { "version": "0.55" }
}
Verify the exact field names against the live docs before relying on this — fields are still settling.
NLWeb uses Server-Sent Events when streaming=true (the default):
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
X-Accel-Buffering: no
Each chunk is:
data: <json>\n\n
The <json> is one of:
{"message_type": "license", "content": {...}}{"results": [...]} (results may arrive incrementally as FastTrack streams){"query_id": "...", "complete": true} (exact field — verify live)NLWeb's "headers" are NOT HTTP response headers — they are JSON objects in the SSE stream with a message_type discriminator. Known types:
| message_type | Purpose |
|---|---|
license | Content license terms |
data_retention | How long the agent may cache results |
cache_policy | Caching directives |
ui_component | Optional rendering hint |
usage_terms | Acceptable use |
rate_limits | Calls/sec / day budget |
data_freshness | When the underlying data was last indexed |
api_version | Server's NLWeb version |
Client parsing rule: don't assume results is the first chunk. Buffer message objects until you see the result stream or a terminal marker.
With streaming=false, the server returns a single application/json body:
{
"query_id": "abc-123",
"messages": [{"message_type": "license", "content": {...}}, ...],
"results": [
{
"url": "https://example.com/article/x",
"name": "Article X",
"site": "example",
"score": 0.83,
"description": "...",
"schema_object": { "@type": "Article", "@context": "https://schema.org", ... }
}
]
}
The schema_object is the original Schema.org JSON-LD that was indexed — this is what makes NLWeb results agent-actionable, not just text snippets.
| Mode | Behavior | Use case |
|---|---|---|
list | Return ranked Schema.org results, no LLM synthesis | Agent does its own rendering / re-ranking |
summarize | LLM condenses top results into a short answer + still returns results | Conversational UIs |
generate | Full RAG — LLM synthesizes an answer grounded in results | Q&A endpoints |
For /ask, errors generally come back as 500 with a JSON envelope. For /mcp, errors use JSON-RPC 2.0:
{
"jsonrpc": "2.0",
"id": 1,
"error": { "code": -32603, "message": "Internal error", "data": {...} }
}
Always check status code before parsing — partial SSE streams can drop with 200 followed by silence.
If you need to extend /ask (e.g., add an auth check or custom param):
webserver/routes/api.pywebserver/middleware/ rather than modifying the route directly — keeps you upgrade-safeNLWebHandler (core/baseHandler.py) unchanged so the streaming + ranking pipeline still runs# Python streaming client (sketch — verify response shape against the live spec)
import httpx, json
async with httpx.AsyncClient() as client:
async with client.stream("GET", "http://localhost:8000/ask",
params={"query": "best running shoes", "site": "shoes", "mode": "generate"}) as r:
async for line in r.aiter_lines():
if not line.startswith("data: "):
continue
obj = json.loads(line[6:])
if "message_type" in obj:
handle_header(obj)
elif "results" in obj:
handle_results(obj["results"])
mode=listmode=summarizemode=generatestreaming=false first — easier to inspect a single JSON body.decontextualized_query to bypass query rewriting and isolate ranking issues.mode=list to see the raw retrieval — if results are bad here, the problem is ingest/embeddings, not the LLM.query_id and grep server logs for it.tool_selection_enabled in config_nlweb.yaml to bypass the router and force straight retrieval.Always verify the exact param names and message_type values against the live spec — they evolve.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin nlweb-protocol13 skills in this plugin
/nlweb-auth-multitenancyConfigure NLWeb authentication and multi-tenant deployments — OAuth providers (GitHub, Google, Microsoft, Facebook), session storage, the `sites:` allowlist in `config_nlweb.yaml`, conversation persistence per authenticated user, and per-tenant data isolation. Use when adding login to an NLWeb instance, hosting multiple customers on one deployment, or persisting conversation history./nlweb-chatgpt-appsdkIntegrate NLWeb with ChatGPT's Apps SDK — the Node.js MCP server in `openai-apps-sdk-integration/`, the `nlweb-list` tool, the React widget at `ui://widget/nlweb-list.html`, and the port-8100 AppSDK adapter that translates NLWeb's message list to OpenAI Apps SDK envelopes. Use when publishing an NLWeb site as a ChatGPT app or wiring NLWeb results into an Apps SDK widget./nlweb-data-loadingIngest site content into NLWeb's vector store using `db_load.py` — supports RSS/Atom feeds, Schema.org JSON-LD, sitemap-driven URL lists, and CSV. Covers chunking, embedding computation, site partitioning, batch sizing, delete-and-reload, and per-backend write_endpoint targeting. Use when bootstrapping a site's index, refreshing content, or migrating between retrieval backends./nlweb-deploymentDeploy NLWeb to production — Azure App Service (`deploy_azure_webapp.sh` + AI Search + Azure OpenAI), Snowflake Container Services, Cloudflare Worker + AutoRAG, Docker, and self-hosted. Covers env-var conventions, `mode: production` lockdown, scaling, TLS, OAuth, and CI for data reloads. Use when going from local dev to a hosted, internet-facing NLWeb instance./nlweb-dev-patternsNLWeb development patterns — the mixed-mode programming philosophy, FastTrack vs Analysis parallel paths, config file precedence and the `mode: development` override trap, in-stream NLWS headers vs HTTP headers, embedding/ingest determinism, debugging the LLM-call chain, neural scorer selection (NLWebScorer ModernBERT+GAM), and the A2A / AgentFinder / DataFinder / ModelRouter subsystems. Use when designing the internal architecture of an NLWeb deployment or solving cross-cutting concerns./nlweb-llm-providersConfigure NLWeb LLM and embedding providers — OpenAI, Azure OpenAI (default), Anthropic, Google Gemini, DeepSeek on Azure, Llama on Azure, HuggingFace, Inception Labs, Snowflake Cortex, Ollama, Pi Labs. Covers `config_llm.yaml` high/low tier model selection, the ModelRouter cost/quality routing logic, `config_embedding.yaml`, and adding a custom provider. Use when picking models, tuning cost, or wiring a new LLM backend.Other plugins' skills for the same job