[{"data":1,"prerenderedAt":807},["ShallowReactive",2],{"navigation_docs":3,"-guide-http":60,"-guide-http-surround":802},[4,32],{"title":5,"path":6,"stem":7,"children":8,"icon":31},"Guide","\u002Fguide","1.guide\u002F01.index",[9,11,15,19,23,27],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Defining Tools","\u002Fguide\u002Fdefining-tools","1.guide\u002F02.defining-tools",{"title":16,"path":17,"stem":18},"Validation and Errors","\u002Fguide\u002Fvalidation","1.guide\u002F03.validation",{"title":20,"path":21,"stem":22},"CLI","\u002Fguide\u002Fcli","1.guide\u002F04.cli",{"title":24,"path":25,"stem":26},"HTTP","\u002Fguide\u002Fhttp","1.guide\u002F05.http",{"title":28,"path":29,"stem":30},"Moving a Package Over","\u002Fguide\u002Fmigrating","1.guide\u002F06.migrating","i-lucide-book-open",{"title":33,"path":34,"stem":35,"children":36,"icon":59},"Hosts","\u002Fhosts","2.hosts\u002F00.index",[37,39,43,47,51,55],{"title":38,"path":34,"stem":35},"Every host",{"title":40,"path":41,"stem":42},"MCP","\u002Fhosts\u002Fmcp","2.hosts\u002F01.mcp",{"title":44,"path":45,"stem":46},"Pi","\u002Fhosts\u002Fpi","2.hosts\u002F02.pi",{"title":48,"path":49,"stem":50},"OMP","\u002Fhosts\u002Fomp","2.hosts\u002F03.omp",{"title":52,"path":53,"stem":54},"AI SDK","\u002Fhosts\u002Fai-sdk","2.hosts\u002F04.ai-sdk",{"title":56,"path":57,"stem":58},"OpenCode","\u002Fhosts\u002Fopencode","2.hosts\u002F05.opencode","i-lucide-table",{"id":61,"title":62,"body":63,"description":793,"extension":794,"links":795,"meta":796,"navigation":798,"path":25,"seo":799,"stem":26,"__hash__":801},"docs\u002F1.guide\u002F05.http.md","Plain HTTP",{"type":64,"value":65,"toc":784},"minimark",[66,70,75,102,121,297,301,315,324,328,334,340,343,349,353,378,385,538,544,548,558,561,615,618,622,635,652,663,669,685,697,703,706,728,738,742,752,766,780],[67,68,69],"p",{},"A GTK app, script or dashboard can call your tools with a plain POST and get JSON back. Making a GTK app learn an MCP handshake just to call a tool is overkill. Want to give it a simpler door?",[71,72,74],"h2",{"id":73},"mount-the-handler","Mount the handler",[67,76,77,78,82,83,86,87,90,91,93,94,97,98,101],{},"Import ",[79,80,81],"code",{},"createHttpHandler"," from ",[79,84,85],{},"@agntn\u002Ftools\u002Fhttp",". Pass it ",[79,88,89],{},"info",", the tools and options. ",[79,92,89],{}," is just a ",[79,95,96],{},"name"," and a ",[79,99,100],{},"version",".",[67,103,104,105,108,109,112,113,116,117,120],{},"You get a Fetch handler with a ",[79,106,107],{},"fetch(request)"," method. It takes a ",[79,110,111],{},"Request"," and returns a ",[79,114,115],{},"Response",". Any host that speaks Fetch can mount it. Here, h3 mounts it at ",[79,118,119],{},"\u002Fhttp\u002Fslugs",":",[122,123,129],"pre",{"className":124,"code":125,"filename":126,"language":127,"meta":128,"style":128},"language-ts shiki shiki-themes tools tools tools","import { H3, serve } from \"h3\";\nimport { createHttpHandler } from \"@agntn\u002Ftools\u002Fhttp\";\nimport { slugTool } from \".\u002Ftools.ts\";\n\nconst http = createHttpHandler({ name: \"slugs\", version: \"1.0.0\" }, [slugTool], {\n  base: \"\u002Fhttp\u002Fslugs\",\n});\n\nconst app = new H3().all(\"\u002Fhttp\u002Fslugs\u002F**\", (event) => http.fetch(event.req));\nserve(app, { port: 3000 });\n","server.ts","ts","",[79,130,131,154,169,184,191,222,234,240,245,288],{"__ignoreMap":128},[132,133,136,140,144,147,151],"span",{"class":134,"line":135},"line",1,[132,137,139],{"class":138},"skH_V","import",[132,141,143],{"class":142},"s38Sx"," { H3, serve } ",[132,145,146],{"class":138},"from",[132,148,150],{"class":149},"shU9J"," \"h3\"",[132,152,153],{"class":142},";\n",[132,155,157,159,162,164,167],{"class":134,"line":156},2,[132,158,139],{"class":138},[132,160,161],{"class":142}," { createHttpHandler } ",[132,163,146],{"class":138},[132,165,166],{"class":149}," \"@agntn\u002Ftools\u002Fhttp\"",[132,168,153],{"class":142},[132,170,172,174,177,179,182],{"class":134,"line":171},3,[132,173,139],{"class":138},[132,175,176],{"class":142}," { slugTool } ",[132,178,146],{"class":138},[132,180,181],{"class":149}," \".\u002Ftools.ts\"",[132,183,153],{"class":142},[132,185,187],{"class":134,"line":186},4,[132,188,190],{"emptyLinePlaceholder":189},true,"\n",[132,192,194,197,200,203,207,210,213,216,219],{"class":134,"line":193},5,[132,195,196],{"class":138},"const",[132,198,199],{"class":142}," http ",[132,201,202],{"class":138},"=",[132,204,206],{"class":205},"sK71F"," createHttpHandler",[132,208,209],{"class":142},"({ name: ",[132,211,212],{"class":149},"\"slugs\"",[132,214,215],{"class":142},", version: ",[132,217,218],{"class":149},"\"1.0.0\"",[132,220,221],{"class":142}," }, [slugTool], {\n",[132,223,225,228,231],{"class":134,"line":224},6,[132,226,227],{"class":142},"  base: ",[132,229,230],{"class":149},"\"\u002Fhttp\u002Fslugs\"",[132,232,233],{"class":142},",\n",[132,235,237],{"class":134,"line":236},7,[132,238,239],{"class":142},"});\n",[132,241,243],{"class":134,"line":242},8,[132,244,190],{"emptyLinePlaceholder":189},[132,246,248,250,253,255,258,261,264,267,270,273,276,279,282,285],{"class":134,"line":247},9,[132,249,196],{"class":138},[132,251,252],{"class":142}," app ",[132,254,202],{"class":138},[132,256,257],{"class":138}," new",[132,259,260],{"class":205}," H3",[132,262,263],{"class":142},"().",[132,265,266],{"class":205},"all",[132,268,269],{"class":142},"(",[132,271,272],{"class":149},"\"\u002Fhttp\u002Fslugs\u002F**\"",[132,274,275],{"class":142},", (event) ",[132,277,278],{"class":138},"=>",[132,280,281],{"class":142}," http.",[132,283,284],{"class":205},"fetch",[132,286,287],{"class":142},"(event.req));\n",[132,289,291,294],{"class":134,"line":290},10,[132,292,293],{"class":205},"serve",[132,295,296],{"class":142},"(app, { port: 3000 });\n",[71,298,300],{"id":299},"list-the-tools","List the tools",[67,302,303,304,307,308,311,312,314],{},"A GET at the root lists the server name, version and tools. Each tool has a name, title, description, effect and ",[79,305,306],{},"inputSchema",". With ",[79,309,310],{},"base"," set to ",[79,313,119],{},", the listing lives there:",[122,316,322],{"className":317,"code":319,"filename":320,"language":321,"meta":128},[318],"language-text","$ curl -s http:\u002F\u002Flocalhost:3000\u002Fhttp\u002Fslugs | jq\n{\n  \"name\": \"slugs\",\n  \"version\": \"1.0.0\",\n  \"tools\": [\n    {\n      \"name\": \"text_slug\",\n      \"title\": \"Text Slug\",\n      \"description\": \"Turn a title into a lowercase URL slug.\",\n      \"effect\": \"read\",\n      \"inputSchema\": {\n        \"type\": \"object\",\n        \"required\": [\n          \"text\"\n        ],\n        \"properties\": {\n          \"text\": {\n            \"type\": \"string\",\n            \"minLength\": 1\n          }\n        },\n        \"additionalProperties\": false\n      }\n    }\n  ]\n}\n","terminal","text",[79,323,319],{"__ignoreMap":128},[71,325,327],{"id":326},"call-a-tool","Call a tool",[67,329,330,331,101],{},"POST to the tool's name under the base path. Send its input as JSON. An empty body counts as ",[79,332,333],{},"{}",[122,335,338],{"className":336,"code":337,"filename":320,"language":321,"meta":128},[318],"$ curl -s -H 'content-type: application\u002Fjson' -d '{\"text\":\"Hello, World\"}' http:\u002F\u002Flocalhost:3000\u002Fhttp\u002Fslugs\u002Ftext_slug\n{\"text\":\"hello-world\",\"details\":{\"slug\":\"hello-world\"}}\n",[79,339,337],{"__ignoreMap":128},[67,341,342],{},"The core checks input before calling the tool, just as it does on other hosts. A typo gets the same error lines MCP would return:",[122,344,347],{"className":345,"code":346,"filename":320,"language":321,"meta":128},[318],"$ curl -s -w '\\n%{http_code}\\n' -H 'content-type: application\u002Fjson' -d '{\"txt\":\"Hello, World\"}' http:\u002F\u002Flocalhost:3000\u002Fhttp\u002Fslugs\u002Ftext_slug\n{\"lines\":[\"Invalid arguments: unknown property \\\"txt\\\"; takes text\",\"Invalid arguments at \u002F: must have required properties text\"]}\n400\n",[79,348,346],{"__ignoreMap":128},[71,350,352],{"id":351},"what-comes-back","What comes back?",[67,354,355,356,358,359,362,363,366,367,370,371,358,374,377],{},"A tool answer has ",[79,357,321],{}," and ",[79,360,361],{},"details",". It's 200, or 422 if the tool set ",[79,364,365],{},"isError",". Both fields stay in the answer. Results with image blocks also include ",[79,368,369],{},"images",", an array of ",[79,372,373],{},"data",[79,375,376],{},"mimeType"," objects.",[67,379,380,381,384],{},"A refusal has ",[79,382,383],{},"lines"," instead. Each line is a separate entry. Newlines inside an error message become spaces, so they can't forge another line.",[386,387,388,404],"table",{},[389,390,391],"thead",{},[392,393,394,398,401],"tr",{},[395,396,397],"th",{},"Status",[395,399,400],{},"Body",[395,402,403],{},"When",[405,406,407,421,435,448,463,475,491,507,522],"tbody",{},[392,408,409,413,418],{},[410,411,412],"td",{},"200",[410,414,415],{},[79,416,417],{},"{ text, details }",[410,419,420],{},"the tool answered",[392,422,423,426,430],{},[410,424,425],{},"422",[410,427,428],{},[79,429,417],{},[410,431,432,433],{},"the tool set ",[79,434,365],{},[392,436,437,440,445],{},[410,438,439],{},"400",[410,441,442],{},[79,443,444],{},"{ lines }",[410,446,447],{},"bad input, or a body that isn't JSON",[392,449,450,453,457],{},[410,451,452],{},"403",[410,454,455],{},[79,456,444],{},[410,458,459,460],{},"the tool's effect isn't in ",[79,461,462],{},"effects",[392,464,465,468,472],{},[410,466,467],{},"404",[410,469,470],{},[79,471,444],{},[410,473,474],{},"no such tool, or nothing at that path",[392,476,477,480,484],{},[410,478,479],{},"405",[410,481,482],{},[79,483,444],{},[410,485,486,487,490],{},"wrong method, ",[79,488,489],{},"Allow"," names the right one",[392,492,493,496,500],{},[410,494,495],{},"413",[410,497,498],{},[79,499,444],{},[410,501,502,503,506],{},"body over ",[79,504,505],{},"maxRequestBodySize",", 4 MiB by default",[392,508,509,512,516],{},[410,510,511],{},"415",[410,513,514],{},[79,515,444],{},[410,517,518,519],{},"no ",[79,520,521],{},"Content-Type: application\u002Fjson",[392,523,524,527,531],{},[410,525,526],{},"500",[410,528,529],{},[79,530,444],{},[410,532,533,534,537],{},"the tool threw, ",[79,535,536],{},"caused by:"," lines included",[67,539,540,541,543],{},"The body needs ",[79,542,521],{},", or the handler returns 415. A browser page can't send that header across origins without a CORS preflight. This handler never answers one.",[71,545,547],{"id":546},"writes-stay-off","Writes stay off",[67,549,550,551,553,554,557],{},"The ",[79,552,462],{}," option defaults to ",[79,555,556],{},"[\"read\"]",". An HTTP call has nobody there to click \"approve\". Write tools stay out of the listing and return 403.",[67,559,560],{},"You can turn writes on:",[122,562,564],{"className":124,"code":563,"filename":126,"language":127,"meta":128,"style":128},"const http = createHttpHandler({ name: \"slugs\", version: \"1.0.0\" }, [slugTool], {\n  base: \"\u002Fhttp\u002Fslugs\",\n  effects: [\"read\", \"write\"],\n});\n",[79,565,566,586,594,611],{"__ignoreMap":128},[132,567,568,570,572,574,576,578,580,582,584],{"class":134,"line":135},[132,569,196],{"class":138},[132,571,199],{"class":142},[132,573,202],{"class":138},[132,575,206],{"class":205},[132,577,209],{"class":142},[132,579,212],{"class":149},[132,581,215],{"class":142},[132,583,218],{"class":149},[132,585,221],{"class":142},[132,587,588,590,592],{"class":134,"line":156},[132,589,227],{"class":142},[132,591,230],{"class":149},[132,593,233],{"class":142},[132,595,596,599,602,605,608],{"class":134,"line":171},[132,597,598],{"class":142},"  effects: [",[132,600,601],{"class":149},"\"read\"",[132,603,604],{"class":142},", ",[132,606,607],{"class":149},"\"write\"",[132,609,610],{"class":142},"],\n",[132,612,613],{"class":134,"line":186},[132,614,239],{"class":142},[67,616,617],{},"Only do that behind your host's authentication.",[71,619,621],{"id":620},"stream-progress-over-http","Stream progress over HTTP",[67,623,624,625,628,629,358,632,101],{},"Want to see a call make progress? Send your usual POST with ",[79,626,627],{},"Accept: text\u002Fevent-stream",". You'll get Server-Sent Events with ",[79,630,631],{},"Content-Type: text\u002Fevent-stream",[79,633,634],{},"Cache-Control: no-cache",[67,636,637,638,641,642,645,646,358,648,651],{},"Each ",[79,639,640],{},"progress"," event carries ",[79,643,644],{},"message",", plus ",[79,647,640],{},[79,649,650],{},"total"," when they're numbers. HTTP doesn't renumber or drop updates. That's handy for a slow call: you can tell it's still working.",[67,653,654,655,658,659,662],{},"Here a ",[79,656,657],{},"job_wait"," tool, mounted at ",[79,660,661],{},"\u002Fhttp\u002Fjobs",", checks a build three times:",[122,664,667],{"className":665,"code":666,"filename":320,"language":321,"meta":128},[318],"$ curl -sN -H 'accept: text\u002Fevent-stream' -H 'content-type: application\u002Fjson' -d '{\"id\":\"build-42\"}' http:\u002F\u002Flocalhost:3000\u002Fhttp\u002Fjobs\u002Fjob_wait\nevent: progress\ndata: {\"message\":\"build-42 still running, check 1\",\"progress\":1,\"total\":3}\n\nevent: progress\ndata: {\"message\":\"build-42 still running, check 2\",\"progress\":2,\"total\":3}\n\nevent: progress\ndata: {\"message\":\"build-42 still running, check 3\",\"progress\":3,\"total\":3}\n\nevent: result\ndata: {\"status\":200,\"text\":\"build-42 is done\",\"details\":{\"id\":\"build-42\",\"checks\":3}}\n",[79,668,666],{"__ignoreMap":128},[67,670,671,672,675,676,678,679,645,681,684],{},"The stream ends with one ",[79,673,674],{},"result"," event. It carries the usual ",[79,677,417],{}," or ",[79,680,444],{},[79,682,683],{},"status",". The status rides in the result because the headers already left with the first event. Close the stream halfway and the read stops with it.",[67,686,687,688,690,691,694,695,101],{},"Bad tool input arrives as a ",[79,689,674],{}," with ",[79,692,693],{},"status: 400"," and the usual ",[79,696,383],{},[122,698,701],{"className":699,"code":700,"filename":320,"language":321,"meta":128},[318],"$ curl -sN -H 'accept: text\u002Fevent-stream' -H 'content-type: application\u002Fjson' -d '{\"di\":\"build-42\"}' http:\u002F\u002Flocalhost:3000\u002Fhttp\u002Fjobs\u002Fjob_wait\nevent: result\ndata: {\"status\":400,\"lines\":[\"Invalid arguments: unknown property \\\"di\\\"; takes id\",\"Invalid arguments at \u002F: must have required properties id\"]}\n",[79,702,700],{"__ignoreMap":128},[67,704,705],{},"Some refusals happen before the call starts. These stay plain JSON, even when you ask for events:",[707,708,709,713,716,719,722,725],"ul",{},[710,711,712],"li",{},"Unknown tool: 404.",[710,714,715],{},"Wrong method: 405.",[710,717,718],{},"Write tool not served: 403.",[710,720,721],{},"Missing JSON content type: 415.",[710,723,724],{},"Oversized body: 413.",[710,726,727],{},"Body that isn't JSON: 400.",[67,729,730,731,734,735,101],{},"Without the header, you'll get one JSON answer at the end. ",[79,732,733],{},"Accept: *\u002F*"," doesn't request events. Neither does ",[79,736,737],{},"text\u002Fevent-stream;q=0",[71,739,741],{"id":740},"whos-calling","Who's calling?",[67,743,744,745,604,748,751],{},"Authentication belongs to the host. Check ",[79,746,747],{},"Host",[79,749,750],{},"Origin"," and a token before the request reaches the handler.",[67,753,754,755,690,758,761,762,765],{},"Tools receive ",[79,756,757],{},"host",[79,759,760],{},"http: true"," and the ",[79,763,764],{},"request",", so they can read its headers. But client headers are name tags, not keys. They can identify a caller, not authorize one.",[67,767,768,769,772,773,775,776,779],{},"The request's ",[79,770,771],{},"signal"," becomes the call's ",[79,774,771],{},". If the host aborts it when the client hangs up, a read is cancelled. h3 does. Progress is available only on a streamed call, which makes a long wait easier to follow. But ",[79,777,778],{},"ask"," is absent: an HTTP form has nobody to fill it in.",[781,782,783],"style",{},"html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":128,"searchDepth":156,"depth":156,"links":785},[786,787,788,789,790,791,792],{"id":73,"depth":156,"text":74},{"id":299,"depth":156,"text":300},{"id":326,"depth":156,"text":327},{"id":351,"depth":156,"text":352},{"id":546,"depth":156,"text":547},{"id":620,"depth":156,"text":621},{"id":740,"depth":156,"text":741},"Serve the same tools as JSON over plain HTTP. One GET lists them, one POST calls one, and writes stay off until you say so","md",null,{"icon":797},"i-lucide-globe",{"title":24},{"title":800,"description":793},"Call your tools over plain HTTP, no MCP handshake","MN4lTVUtzKebjnljbSzYS1MpgKsDjomS0YaUhjVTaUI",[803,805],{"title":20,"path":21,"stem":22,"description":804,"children":-1},"Turn the same tool list into a command line. Flags come from the schema and MCP rides along",{"title":28,"path":29,"stem":30,"description":806,"children":-1},"Take a package that declares its tools four times and bring it down to one definition. Step by step with the traps marked",1796479391523]