{"name":"mcp_echo_server_http.nu","source":"// mcp_echo_server_http.nu — the same MCP server over Streamable HTTP.\n//\n// Identical to examples/mcp_echo_server.nu down to the last\n// registration; only the last call differs. That is the point: the\n// transport is a choice made in one line, not a second implementation\n// of the protocol. See that file for what each registration does.\n//\n// Run by hand:\n//\n//     ./build.sh   # or .\\build.bat on Windows\n//     ./nurl.sh examples/mcp_echo_server_http.nu &\n//\n// Then probe via curl:\n//\n//     curl -s -X POST http://127.0.0.1:18770/mcp \\\n//          -H 'Content-Type: application/json' \\\n//          --data '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{}}'\n//     curl -s -X POST http://127.0.0.1:18770/mcp \\\n//          -H 'Content-Type: application/json' \\\n//          --data '{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\"}'\n//     curl -s -X POST http://127.0.0.1:18770/mcp \\\n//          -H 'Content-Type: application/json' \\\n//          --data '{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"echo\",\"arguments\":{\"text\":\"hello\"}}}'\n//\n// Bind to 0.0.0.0 instead of 127.0.0.1 to expose on the LAN, and pass a\n// non-empty token to require `Authorization: Bearer <token>` (compared\n// in constant time). For TLS, put NURL behind nginx/caddy or build the\n// listener yourself with `tcp_listen_tls` from ext/http_server.nu and\n// hand `mcp_server_http_dispatch`'s closure to `mcp_http_handler` —\n// which is all `mcp_server_serve_http` does.\n\n$ `stdlib/ext/mcp.nu`\n$ `stdlib/ext/mcp_server.nu`\n$ `stdlib/std/net.nu`\n$ `stdlib/core/string.nu`\n\n@ echo_tool Json args → Json {\n    : ?Json text_j ( json_obj_get args `text` )\n    ?? text_j {\n        T tv → { ^ ( mcp_tool_result_text ( json_str_data tv ) ) }\n        F _ → { ^ ( mcp_tool_result_error `missing required argument: text` ) }\n    }\n}\n\n@ main → i {\n    : McpServer srv ( mcp_server_new `nurl-echo` `1.0.0` )\n    ( mcp_server_set_instructions srv\n    `One tool, echo, which returns the text you give it. Useful as a\nconnectivity check before trying anything that costs something.` )\n    ( mcp_server_add_tool_full srv `echo`\n    `Echo the supplied text back to the caller.`\n    ( mcp_schema_of1 `text` `string` `Text to echo` T )\n    T F T F\n    \\ Json a → Json { ^ ( echo_tool a ) } )\n\n    ( mcp_log `nurl-echo-mcp-http 0.2.0 listening on 127.0.0.1:18770/mcp` )\n    : ~ i rc 0\n    // The empty token serves unauthenticated; pass one to require a\n    // bearer header on every request.\n    ?? ( mcp_server_serve_http srv `127.0.0.1` 18770 `` ) {\n        T _ → {}\n        F e → {\n            ( mcp_log ( nurl_str_cat `server error: ` ( net_err_name e ) ) )\n            = rc 1\n        }\n    }\n    ^ rc\n}\n","bytes":2710}