/**
 * MCP server entrypoint for the url-get plugin. Registers one tool, `url-get`,
 * on the standard stdio transport. Module init must never throw on missing
 * per-account env — plugin-system spawn enumerates tools/list with empty env,
 * and any boot throw empties the registry. The tool reads ACCOUNT_DIR at call
 * time and returns an error envelope when storage cannot be resolved.
 */
import { initStderrTee } from "../../../../lib/mcp-stderr-tee/dist/index.js";
initStderrTee("url-get");
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { eagerTool } from "../../../../lib/mcp-eager/dist/index.js";
import { z } from "zod";
import { urlGet } from "./tools/url-get.js";
const server = new McpServer({
    name: "url-get",
    version: "0.1.0",
});
eagerTool(server, "url-get", "Fetch a server-rendered web page with no model in the path. The page is fetched over HTTP and cleaned to markdown, then written verbatim to an account-scoped reference file (the faithful ground-truth copy). Returns { text, referencePath }: `text` is that cleaned markdown capped at 100k chars, `referencePath` is the full verbatim copy on disk. There is no summary and no subprocess — if you need a summary, invoke url-get from a delegated subagent so the full text stays in the subagent's context and only the summary returns to the main agent. For a large page, grep the reference file for specific passages rather than reading the whole `text`. Use this instead of WebFetch when you need a faithful copy of a page (e.g. ingesting the operator's own writing) — WebFetch refuses to reproduce copyrighted text. Handles server-rendered HTML only (no JavaScript execution); an empty `text` with textLength=0 means a JavaScript-rendered shell, so retry with the browser MCP. A page that returns a bot-challenge or empty body fails with an explicit error and writes no file.", {
    url: z.string().url().describe("Absolute http(s) URL of the page to fetch."),
}, async (args) => {
    const result = await urlGet(args);
    if (!result.ok) {
        return {
            isError: true,
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
        };
    }
    return {
        content: [
            {
                type: "text",
                text: JSON.stringify({
                    text: result.text,
                    referencePath: result.referencePath,
                    url: result.url,
                    httpStatus: result.httpStatus,
                    bytes: result.bytes,
                    textLength: result.textLength,
                }, null, 2),
            },
        ],
    };
});
async function main() {
    const transport = new StdioServerTransport();
    await server.connect(transport);
}
main().catch((err) => {
    console.error("[url-get] fatal:", err);
    process.exit(1);
});
//# sourceMappingURL=index.js.map