# @cubicecho/discovery-core > The shared core of the cubicecho discovery packages: serving and fetching public discovery documents, and mDNS advertising and browsing on one responder per process. Agent-facing docs for @cubicecho/discovery-core: one task or concept per page, then what each package.json "exports" entry exports. Generated from _agents/docs/ and the doc comments in src/ by @cubicecho/agent-docs; edit those, not this file. Requires Node >=22. Peer dependencies: `bonjour-service` >=1.4 (optional), `zod` >=4.1. ## Docs - [Install and entry points](_agents/docs/01-install.md): How to depend on `@cubicecho/discovery-core` from a discovery package, which of its two entry points to import, and when `bonjour-service` is needed. An app that only wants to be found installs `@cubicecho/mcp-discovery` or `@cubicecho/graphql-mdns-discovery` instead. - [Building a discovery package](_agents/docs/building-on-core.md): The rules a package built on `@cubicecho/discovery-core` follows so that an app can use it beside the other discovery packages without clashes. - [Common mistakes](_agents/docs/common-mistakes.md): Mistakes that compile and mostly fail silently when building on `@cubicecho/discovery-core`, each with what happens and the fix. - [Fetching a document](_agents/docs/fetching-documents.md): Fetch and validate a discovery document from a host nobody has vetted, bounded in time and size, and tell the failures apart. - [Advertising on the LAN](_agents/docs/mdns-advertising.md): Announce a DNS-SD service over mDNS, keep the announcement in step with a live setting, and share one responder across everything in the process. - [Browsing the LAN](_agents/docs/mdns-browsing.md): Find hosts advertising a DNS-SD service type, once or continuously, and turn those hosts into the entries their documents list. - [Serving a document](_agents/docs/serving-documents.md): Serve a public JSON discovery document over HTTP with open CORS, a cache lifetime, an ETag and `304`. Pick the function by what you already have: a Node or Express app, a handler that chose to answer, or no Node server at all. - [TXT records](_agents/docs/txt-records.md): Write and read the TXT record of an advertised service the way every discovery package here does: a layout version, an explicit TLS flag, and paths that can't point at another host. ## Exports: @cubicecho/discovery-core The parts every cubicecho discovery package shares. - `FetchOptions` (type): What every document fetch accepts besides its settings. - `fetchJson`: Fetches a URL and parses its body as JSON, bounded in time and size. - `FETCH_DEFAULTS`: The fetching defaults. - `FetchSettings` (type): How discovery documents are fetched. - `MDNS_DEFAULTS`: The mDNS defaults; probing alone takes about 750 ms. - `MdnsSettings` (type): How mDNS advertising and browsing behave. - `SERVE_DEFAULTS`: The serving defaults; the max age is the one the MCP Server Card spec recommends. - `ServeSettings` (type): How discovery documents are served. - `DiscoveryError`: Any failure to read a discovery document; discovery functions report these per entry. - `DocumentFetchError`: A document could not be fetched: network failure, timeout, an error status or an oversized body. - `InvalidDocumentError`: A document arrived but is not valid JSON, or does not match its schema. - `hostSlug`: A hostname's first label as a slug: lowercase letters, digits and dashes, as a reverse-DNS name's namespace allows. - `parseDocument`: Validates a document against its schema. - `specVersionSchema`: A schema for a document's `specVersion` that accepts any minor of one major. - `DocumentRequest` (type): The parts of a request that decide the response. - `DocumentResponse` (type): A response ready to write to any server. - `documentResponse`: Works out the response to a request for a discovery document. - `answeringMiddleware`: Turns an "answer if it is mine" function into middleware. - `DocumentHandler` (type): A Node request handler; it rejects when the document source throws. - `DocumentMiddleware` (type): Express-style middleware: it answers the requests it owns and passes every other request to `next`. - `DocumentSource` (type): Where a handler gets the document it serves, asked once per request so it can follow config changes. - `documentHandler`: A handler that serves one kind of discovery document. - `requestPath`: The path a request asks for, without its query string. - `writeDocument`: Writes a discovery document as the response to a request. - `requestOrigin`: The `scheme://host[:port]` a request was addressed to, from its `Host` header. ## Exports: @cubicecho/discovery-core/mdns LAN advertising and browsing over mDNS / DNS-SD, for any service type, on one responder per process. - `AdvertiseError`: The announcement did not go out in time, most often because the name is already in use on the network. - `Advertisement` (type): A running advertisement. - `advertiseService`: Advertises a DNS-SD service, resolving once the announcement has gone out. - `ServiceAnnouncement` (type): One service to advertise. - `Advertiser` (type): Keeps the announcement in step with `isWanted()`. - `AdvertiserDeps` (type): What the advertiser needs from its host. - `AdvertiserOptions` (type): What every advertiser's options carry, whatever the service type. - `createAdvertiser`: An advertiser that announces nothing until the first `sync`. - `FoundHost` (type): A host found on the network: where it is, and what its TXT record said. - `FoundService` (type): What a found service has that a host reader reads. - `findServices`: Listens for one service type for a while, then lists what answered. - `ServiceBrowse` (type): What to browse for, and how to read what is found. - `ServiceWatch` (type): A running watch. - `ServiceWatchHandlers` (type): What a service watch tells its caller. - `toFoundHost`: Turns a found service into a host, given how to read its TXT record. - `watchServices`: Browses for one service type until stopped, reporting each host as it comes and goes. - `createEntryTracker`: A tracker that reports entries through `handlers`. - `EntrySource` (type): How the tracker reads hosts and tells entries apart. - `EntryTracker` (type): Tracks the entries on a set of hosts. - `EntryWatchHandlers` (type): What an entry watch tells its caller. - `HostRead` (type): What one read of a host's document gave. - `acquireResponder`: Opens the shared responder, or joins the one already open. - `ResponderLease` (type): A hold on the shared responder; release it when done. - `responderHolders`: How many leases the shared responder has open, for tests and diagnostics. - `assertLocalPaths`: Checks paths about to be advertised, since a client resolves each one against the host. - `FLAG_ON`: The value a flag key carries when it is on; a bare key does not survive bonjour-service's decoding. - `isLocalPath`: Whether a value from the network is safe to resolve against the host as a path. - `readTxtFlag`: Reads a flag from a TXT record. - `readTxtPath`: Reads a path from a TXT record, falling back when it is missing or unsafe. - `TXT_TLS_KEY`: The key present, set to FLAG_ON, when the advertised host speaks HTTPS. - `TXT_VERSION_KEY`: The key that carries a record's layout version. - `EntryWatch` (type): A running entry watch. - `watchEntries`: Watches the network for the entries hosts of one service type list, reporting each as it appears, changes and goes.