Add Streamable HTTP MCP and harden web /v1 invoke auth.
agent_mcp_serve gains http transport; invoke injects Bearer/X-Api-Key and maps unauthorized to 401; openai/agent field access prefers json.get over footnotes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b43a08b2e2
commit
8353ba38fe
8 files changed
+525
-112
No files matched your search
+40
-34
@@ -66,14 +66,14 @@ One LLM turn via the semantic surface (`ask` / `stream`+`collect`). Returns `{te
|
||||
**err = None**
|
||||
**calls = 1**
|
||||
1. not `text`
|
||||
**e0 = [1](evs)**
|
||||
**e0 = > at value=`evs` index=0**
|
||||
**err = > json.get value=`e0` key="message"**
|
||||
1. `err`
|
||||
**calls = 0**
|
||||
2. *
|
||||
**r = > model.ask prompt=`prompt`**
|
||||
**text = [text](r)**
|
||||
**tokens = [tokens](r)**
|
||||
**text = > json.get value=`r` key="text"**
|
||||
**tokens = > json.get value=`r` key="tokens"**
|
||||
**err = > json.get value=`r` key="error"**
|
||||
**fin = > json.get value=`r` key="finish"**
|
||||
1. `tokens`
|
||||
@@ -181,7 +181,7 @@ Allowlist check, then invoke the runbook `##` via `lib/subtask` (`spawn fn=` →
|
||||
Build a runnable workbook. `skeleton=single` (default): one worker `step`. `skeleton=dual`: research then write agents. On success the parent chooses DONE; runtime `agent_workbook_solidify` freezes the answer.
|
||||
|
||||
**q = > json.quote text=`goal`**
|
||||
**esc = > json.parse text={"h":"---\ntitle: agent workbook\nimport llm:ext/ai/llm.mq.md\nimport agent:ext/ai/agent.mq.md\nimport json:lib/json.mq.md\nimport sys:lib/sys.mq.md\nimport wb:lib/writeback.mq.md\nimport subtask:lib/subtask.mq.md\n---\n\n# Goal\n\nParent goal is embedded as JSON in # main.\n\n## Solidify\n\nWhen the child returns a good value, parent DECISION: DONE — runtime agent_workbook_solidify freezes the answer as **return** (do not invent long FIND/REPLACE).\n\n# main\n\n> llm.load_env\n\n","s1":"\u002a\u0060model\u0060 = > llm.llm \u002a\n","s2":"\u002a\u0060tools\u0060 = > table.empty_list \u002a\n","s3":"\u002a\u0060worker\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You are a workbook worker. tools=[] means never CALL. Finish the task with a direct final answer; do not invent tools. \u002a\n","s4":"\u002a\u0060wrap\u0060 = > json.parse text={\"task\":","s5":"} \u002a\n","s6":"\u002a\u0060task\u0060 = > json.get value=\u0060wrap\u0060 key=task \u002a\n","s7":"\u002a\u0060out\u0060 = > \u0060worker\u0060.step task=\u0060task\u0060 stream=True \u002a\n","s7b":"\u002a\u0060text\u0060 = > json.get value=\u0060out\u0060 key=result \u002a\n","s8":"\u002a\u002a\u0060text\u0060\u002a\u002a\n","d3":"\u002a\u0060research\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You gather facts for the goal. Be concise. Do not invent tools. \u002a\n","d3b":"\u002a\u0060writer\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You write the final answer from research notes. Do not invent tools. \u002a\n","d4":"\u002a\u0060wrap\u0060 = > json.parse text={\"task\":","d5":"} \u002a\n","d6":"\u002a\u0060task\u0060 = > json.get value=\u0060wrap\u0060 key=task \u002a\n","d7":"\u002a\u0060notes\u0060 = > \u0060research\u0060.step task=\u0060task\u0060 stream=True \u002a\n","d8":"\u002a\u0060ns\u0060 = > json.stringify value=\u0060notes\u0060 \u002a\n","d9":"\u002a\u0060wt\u0060 = Write the final answer. Research notes: \u002a\n","d10":"\u002a\u0060wt\u0060 = \u0060wt\u0060 + \u0060ns\u0060 \u002a\n","d11":"\u002a\u0060out\u0060 = > \u0060writer\u0060.step task=\u0060wt\u0060 stream=True \u002a\n","d11b":"\u002a\u0060text\u0060 = > json.get value=\u0060out\u0060 key=result \u002a\n","d12":"\u002a\u002a\u0060text\u0060\u002a\u002a\n"}**
|
||||
**esc = > json.parse text={"h":"---\ntitle: agent workbook\nimport llm:ext/ai/llm.mq.md\nimport agent:ext/ai/agent.mq.md\nimport json:lib/json.mq.md\nimport sys:lib/sys.mq.md\nimport wb:lib/writeback.mq.md\nimport subtask:lib/subtask.mq.md\n---\n\n# Goal\n\nParent goal is embedded as JSON in # main.\n\n## Solidify\n\nWhen the child returns a good value, parent DECISION: DONE — runtime agent_workbook_solidify freezes the answer as **return** (do not invent long FIND/REPLACE).\n\n# main\n\n> llm.load_env\n\n","s1":"\u002a\u0060model\u0060 = > llm.llm \u002a\n","s2":"\u002a\u0060tools\u0060 = > table.empty_list \u002a\n","s3":"\u002a\u0060worker\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You are a workbook worker. tools=[] means never CALL. Finish the task with a direct final answer; do not invent tools. \u002a\n","s4":"\u002a\u0060wrap\u0060 = > json.parse text={\"task\":","s5":"} \u002a\n","s6":"\u002a\u0060task\u0060 = > json.get value=\u0060wrap\u0060 key=task \u002a\n","s7":"\u002a\u0060out\u0060 = > \u0060worker\u0060.step task=\u0060task\u0060 stream=False \u002a\n","s7b":"\u002a\u0060text\u0060 = > json.get value=\u0060out\u0060 key=result \u002a\n","s8":"\u002a\u002a\u0060text\u0060\u002a\u002a\n","d3":"\u002a\u0060research\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You gather facts for the goal. Be concise. Do not invent tools. \u002a\n","d3b":"\u002a\u0060writer\u0060 = > agent.agent model=\u0060model\u0060 tools=\u0060tools\u0060 standing=You write the final answer from research notes. Do not invent tools. \u002a\n","d4":"\u002a\u0060wrap\u0060 = > json.parse text={\"task\":","d5":"} \u002a\n","d6":"\u002a\u0060task\u0060 = > json.get value=\u0060wrap\u0060 key=task \u002a\n","d7":"\u002a\u0060notes\u0060 = > \u0060research\u0060.step task=\u0060task\u0060 stream=False \u002a\n","d8":"\u002a\u0060ns\u0060 = > json.stringify value=\u0060notes\u0060 \u002a\n","d9":"\u002a\u0060wt\u0060 = Write the final answer. Research notes: \u002a\n","d10":"\u002a\u0060wt\u0060 = \u0060wt\u0060 + \u0060ns\u0060 \u002a\n","d11":"\u002a\u0060out\u0060 = > \u0060writer\u0060.step task=\u0060wt\u0060 stream=False \u002a\n","d11b":"\u002a\u0060text\u0060 = > json.get value=\u0060out\u0060 key=result \u002a\n","d12":"\u002a\u002a\u0060text\u0060\u002a\u002a\n"}**
|
||||
**h = > json.get value=`esc` key="h"**
|
||||
**s1 = > json.get value=`esc` key="s1"**
|
||||
**s2 = > json.get value=`esc` key="s2"**
|
||||
@@ -281,8 +281,8 @@ Opt-in CoW trial (O1): open → optional upper write → optional run → diff
|
||||
Host tree unchanged until a successful commit. Return map is a GFM table (link-index readable).
|
||||
|
||||
**sb = sandbox.open root=`root` profile=`profile`**
|
||||
**id = [id](sb)**
|
||||
**prof = [profile](sb)**
|
||||
**id = > json.get value=`sb` key="id"**
|
||||
**prof = > json.get value=`sb` key="profile"**
|
||||
**ok = True**
|
||||
**stdout = ""**
|
||||
**stderr = ""**
|
||||
@@ -297,14 +297,14 @@ Host tree unchanged until a successful commit. Return map is a GFM table (link-i
|
||||
|
||||
1. `source`
|
||||
**ret = sandbox.run id=`id` source=`source`**
|
||||
**ok = [ok](ret)**
|
||||
**stdout = [stdout](ret)**
|
||||
**stderr = [stderr](ret)**
|
||||
**ok = > json.get value=`ret` key="ok"**
|
||||
**stdout = > json.get value=`ret` key="stdout"**
|
||||
**stderr = > json.get value=`ret` key="stderr"**
|
||||
2. `path`
|
||||
**ret = sandbox.run id=`id` path=`path`**
|
||||
**ok = [ok](ret)**
|
||||
**stdout = [stdout](ret)**
|
||||
**stderr = [stderr](ret)**
|
||||
**ok = > json.get value=`ret` key="ok"**
|
||||
**stdout = > json.get value=`ret` key="stdout"**
|
||||
**stderr = > json.get value=`ret` key="stderr"**
|
||||
3. *
|
||||
**_ = 1**
|
||||
|
||||
@@ -360,9 +360,9 @@ With `sandbox=True`, run via `## trial` first (commit on ok); host unchanged unt
|
||||
|
||||
1. `sandbox`
|
||||
**tr = trial path=`path` root=`sandbox_root` profile=`sandbox_profile` commit=True**
|
||||
**ok = [ok](tr)**
|
||||
**stdout = [stdout](tr)**
|
||||
**stderr = [stderr](tr)**
|
||||
**ok = > json.get value=`tr` key="ok"**
|
||||
**stdout = > json.get value=`tr` key="stdout"**
|
||||
**stderr = > json.get value=`tr` key="stderr"**
|
||||
1. `ok`
|
||||
**code = 0**
|
||||
2. *
|
||||
@@ -379,10 +379,10 @@ With `sandbox=True`, run via `## trial` first (commit on ok); host unchanged unt
|
||||
2. *
|
||||
**id = subtask.spawn path=`path`**
|
||||
**waited = subtask.wait id=`id`**
|
||||
**code = [code](waited)**
|
||||
**value = [value](waited)**
|
||||
**stdout = [stdout](waited)**
|
||||
**stderr = [stderr](waited)**
|
||||
**code = > json.get value=`waited` key="code"**
|
||||
**value = > json.get value=`waited` key="value"**
|
||||
**stdout = > json.get value=`waited` key="stdout"**
|
||||
**stderr = > json.get value=`waited` key="stderr"**
|
||||
**obs = inspect_workbook path=`path` exit_code=`code` value=`value` stdout=`stdout` stderr=`stderr`**
|
||||
**out = **
|
||||
|
||||
@@ -1595,7 +1595,7 @@ LLM Plan → CALL/READ/DECISION loop. Returns `{decision,reply,observation,event
|
||||
**evs = > model.stream prompt=`ctx` echo=`echo`**
|
||||
**last_reply = > llm.collect events=`evs`**
|
||||
**evs_all = > plan_merge_deltas events=`evs_all` from=`evs` stream=`stream`**
|
||||
**e0 = [1](evs)**
|
||||
**e0 = > at value=`evs` index=0**
|
||||
**terr = > json.get value=`e0` key="message"**
|
||||
**etype = > json.get value=`e0` key="type"**
|
||||
1. `etype` == "error"
|
||||
@@ -1903,7 +1903,7 @@ Optional `step_kind=` (O3) selects backend via module `## step_route` before the
|
||||
|
||||
1. `step_kind`
|
||||
**sr = step_route kind=`step_kind`**
|
||||
**backend = [backend](sr)**
|
||||
**backend = > json.get value=`sr` key="backend"**
|
||||
2. *
|
||||
**_ = 1**
|
||||
|
||||
@@ -2054,9 +2054,9 @@ Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) o
|
||||
**path = > json.get value=`routed` key="resource"**
|
||||
1. `path`
|
||||
**aw = await_workbook path=`path` sandbox=`sandbox` sandbox_profile=`sandbox_profile`**
|
||||
**code = [code](aw)**
|
||||
**child_val = [value](aw)**
|
||||
**last_obs = [observation](aw)**
|
||||
**code = > json.get value=`aw` key="code"**
|
||||
**child_val = > json.get value=`aw` key="value"**
|
||||
**last_obs = > json.get value=`aw` key="observation"**
|
||||
1. `code` == 0
|
||||
> agent_kb_record_hit kb_dir=`kb_dir` goal=`task` improve_every=`improve_every`
|
||||
**lf = > json.get value=`routed` key="llm_free"**
|
||||
@@ -2094,9 +2094,9 @@ Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) o
|
||||
1. `am`
|
||||
**path = > json.get value=`applied` key="resource"**
|
||||
**aw = await_workbook path=`path` sandbox=`sandbox` sandbox_profile=`sandbox_profile`**
|
||||
**code = [code](aw)**
|
||||
**child_val = [value](aw)**
|
||||
**last_obs = [observation](aw)**
|
||||
**code = > json.get value=`aw` key="code"**
|
||||
**child_val = > json.get value=`aw` key="value"**
|
||||
**last_obs = > json.get value=`aw` key="observation"**
|
||||
1. `code` == 0
|
||||
**exec_mode = "routed"**
|
||||
**sk = > json.get value=`applied` key="skill"**
|
||||
@@ -2153,9 +2153,9 @@ Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) o
|
||||
1. `llm_free`
|
||||
**path = > json.get value=`resolved` key="resource"**
|
||||
**aw = await_workbook path=`path` sandbox=`sandbox` sandbox_profile=`sandbox_profile`**
|
||||
**code = [code](aw)**
|
||||
**child_val = [value](aw)**
|
||||
**last_obs = [observation](aw)**
|
||||
**code = > json.get value=`aw` key="code"**
|
||||
**child_val = > json.get value=`aw` key="value"**
|
||||
**last_obs = > json.get value=`aw` key="observation"**
|
||||
1. `code` == 0
|
||||
> agent_kb_record_hit kb_dir=`kb_dir` goal=`task` improve_every=`improve_every`
|
||||
**exec_mode = "compiled"**
|
||||
@@ -2977,7 +2977,7 @@ Deterministic success stop (loop engineering): when the child already returned a
|
||||
# mcp_server
|
||||
+ `name`=marqdo
|
||||
|
||||
Minimal MCP Server host (stdio JSON-RPC). Tools point at entry-module `lib.member` functions (same bridge as `ext/web` invoke). Evidence/results may carry `authority=workbook`.
|
||||
Minimal MCP Server host (stdio JSON-RPC / Streamable HTTP). Tools point at entry-module `lib.member` functions (same bridge as `ext/web` invoke). Evidence/results may carry `authority=workbook`.
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
@@ -2986,11 +2986,12 @@ Minimal MCP Server host (stdio JSON-RPC). Tools point at entry-module `lib.membe
|
||||
> print text=ext/ai/agent: native agent plugin not found (build marqdo_plugin_agent or marqdo ext add agent)
|
||||
> sys.exit code=1
|
||||
|
||||
**tools0 = > table.empty_list**
|
||||
`h` =
|
||||
|
||||
| _type | tools | name |
|
||||
|-------|-------|------|
|
||||
| mcp_server | [] | `name` |
|
||||
| mcp_server | `tools0` | `name` |
|
||||
|
||||
*h*
|
||||
|
||||
@@ -3002,6 +3003,8 @@ Minimal MCP Server host (stdio JSON-RPC). Tools point at entry-module `lib.membe
|
||||
Register one tool. `fn` must be `lib.member` imported on the entry workbook.
|
||||
|
||||
**tools = > json.get value=`self` key="tools"**
|
||||
1. not `tools`
|
||||
**tools = > table.empty_list**
|
||||
`row` =
|
||||
|
||||
| name | fn | description |
|
||||
@@ -3014,9 +3017,12 @@ Register one tool. `fn` must be `lib.member` imported on the entry workbook.
|
||||
|
||||
## serve
|
||||
+ `transport`=stdio
|
||||
+ `host`="127.0.0.1"
|
||||
+ `port`=7434
|
||||
+ `path`="/mcp"
|
||||
|
||||
Block on stdio MCP (`initialize` / `tools/list` / `tools/call`). HTTP transport is H4b.
|
||||
Block on MCP: `stdio` (line JSON-RPC) or `http` / `streamable-http` (Streamable HTTP, POST JSON-RPC + optional GET SSE). Spec 2025-03-26.
|
||||
|
||||
**name = > json.get value=`self` key="name"**
|
||||
**tools = > json.get value=`self` key="tools"**
|
||||
*> agent_mcp_serve name=`name` tools=`tools` transport=`transport`*
|
||||
*> agent_mcp_serve name=`name` tools=`tools` transport=`transport` host=`host` port=`port` path=`path`*
|
||||
+14
-11
@@ -26,14 +26,14 @@ Collapse a stream event list to final answer text (`done.result` or `error.messa
|
||||
**answer = ""**
|
||||
|
||||
- [ev](events)
|
||||
**t = [type](ev)**
|
||||
**t = > json.get value=`ev` key="type"**
|
||||
1. `t` == "done"
|
||||
**answer = [result](ev)**
|
||||
**answer = > json.get value=`ev` key="result"**
|
||||
2. `t` == "error"
|
||||
**answer = [message](ev)**
|
||||
**answer = > json.get value=`ev` key="message"**
|
||||
3. `t` == "delta"
|
||||
4. `t` == "text"
|
||||
**chunk = [text](ev)**
|
||||
**chunk = > json.get value=`ev` key="text"**
|
||||
1. `chunk`
|
||||
**answer = answer + chunk**
|
||||
2. *
|
||||
@@ -168,7 +168,8 @@ Module convenience: create a default handle and return **answer text**. Pass `pa
|
||||
|
||||
**m = > create model=`model` base_url=`base_url` api_key=`api_key`**
|
||||
**r = > m.ask prompt=`p`**
|
||||
*[text](r)*
|
||||
**_ret = > json.get value=`r` key="text"**
|
||||
*_ret*
|
||||
|
||||
# llm
|
||||
+ `model`=None
|
||||
@@ -306,11 +307,11 @@ Hoist receiver fields before the result table — table cells can shadow `self`
|
||||
column names (`model`, `usage`), so `[model](self)` / `[total_tokens](usage)`
|
||||
inside the table is unsafe.
|
||||
|
||||
**mdl = [model](self)**
|
||||
**b = [backend](self)**
|
||||
**nm = [name](self)**
|
||||
**mdl = > json.get value=`self` key="model"**
|
||||
**b = > json.get value=`self` key="backend"**
|
||||
**nm = > json.get value=`self` key="name"**
|
||||
1. `usage`
|
||||
**tt = [total_tokens](usage)**
|
||||
**tt = > json.get value=`usage` key="total_tokens"**
|
||||
2. *
|
||||
**tt = 0**
|
||||
1. not `tt`
|
||||
@@ -369,10 +370,12 @@ Internal / compatibility primitive. Prefer `ask` / `stream` in new code.
|
||||
|
||||
1. `stream`
|
||||
**pack = > self.complete_result prompt=`prompt` stream=True echo=`echo`**
|
||||
*[events](pack)*
|
||||
**_ret = > json.get value=`pack` key="events"**
|
||||
*_ret*
|
||||
2. *
|
||||
**pack = > self.complete_result prompt=`prompt` stream=False echo=`echo`**
|
||||
*[text](pack)*
|
||||
**_ret = > json.get value=`pack` key="text"**
|
||||
*_ret*
|
||||
|
||||
## chat
|
||||
+ `prompt`
|
||||
|
||||
+14
-11
@@ -104,8 +104,9 @@ POST `/chat/completions` (or stream SSE). Prefers `plugins/llm` ABI (`llm_chat_c
|
||||
**req = > table.put in=`req` at="stream" value=True**
|
||||
**body = > json.stringify value=`req`**
|
||||
**resp = > net.http_post_sse url=`url` body=`body` headers=`headers` echo=`echo`**
|
||||
1. [status](resp) == 200
|
||||
**evs = [events](resp)**
|
||||
**st = > json.get value=`resp` key="status"**
|
||||
1. `st` == 200
|
||||
**evs = > json.get value=`resp` key="events"**
|
||||
|
||||
`pack` =
|
||||
|
||||
@@ -116,11 +117,10 @@ POST `/chat/completions` (or stream SSE). Prefers `plugins/llm` ABI (`llm_chat_c
|
||||
*pack*
|
||||
2. *
|
||||
Soft transport / HTTP failure — structured pack, never abort the VM.
|
||||
**st = [status](resp)**
|
||||
**msg = "HTTP " + `st`**
|
||||
**evs = [events](resp)**
|
||||
**evs = > json.get value=`resp` key="events"**
|
||||
1. `evs`
|
||||
**e0 = [1](evs)**
|
||||
**e0 = > at value=`evs` index=0**
|
||||
**m2 = > json.get value=`e0` key="message"**
|
||||
1. `m2`
|
||||
**msg = `m2`**
|
||||
@@ -134,16 +134,20 @@ POST `/chat/completions` (or stream SSE). Prefers `plugins/llm` ABI (`llm_chat_c
|
||||
2. *
|
||||
**body = > json.stringify value=`req`**
|
||||
**resp = > net.http_post url=`url` body=`body` headers=`headers`**
|
||||
1. [status](resp) == 200
|
||||
**data = > json.parse text=[body](resp)**
|
||||
**msg = [message]([1]([choices](data)))**
|
||||
**st = > json.get value=`resp` key="status"**
|
||||
1. `st` == 200
|
||||
**raw = > json.get value=`resp` key="body"**
|
||||
**data = > json.parse text=`raw`**
|
||||
**choices = > json.get value=`data` key="choices"**
|
||||
**choice0 = > at value=`choices` index=0**
|
||||
**msg = > json.get value=`choice0` key="message"**
|
||||
**text = > json.get value=`msg` key="content"**
|
||||
1. not `text`
|
||||
**text = ""**
|
||||
2. *
|
||||
**_ = 1**
|
||||
**usage = > usage_from data=`data`**
|
||||
**fr = > json.get value=[1]([choices](data)) key="finish_reason"**
|
||||
**fr = > json.get value=`choice0` key="finish_reason"**
|
||||
1. not `fr`
|
||||
**fr = "stop"**
|
||||
2. *
|
||||
@@ -159,8 +163,7 @@ POST `/chat/completions` (or stream SSE). Prefers `plugins/llm` ABI (`llm_chat_c
|
||||
*pack*
|
||||
2. *
|
||||
Soft transport / HTTP failure — structured pack, never abort the VM.
|
||||
**st = [status](resp)**
|
||||
**raw = [body](resp)**
|
||||
**raw = > json.get value=`resp` key="body"**
|
||||
**msg = "HTTP " + `st`**
|
||||
1. `raw`
|
||||
**msg = `msg` + ": " + `raw`**
|
||||
|
||||
Reference in new issue
Block a user