@cubicecho/mcp-discovery
v0.7.0
Published
Advertise and discover MCP servers: Server Cards, AI Catalogs, serving them over HTTP, and finding them from a client.
Maintainers
Readme
@cubicecho/mcp-discovery
Advertise and discover MCP servers.
A server describes itself with an MCP Server Card (SEP-2127): its name, version, and the URLs and
headers it can be reached with. A host lists its cards in an AI Catalog at
/.well-known/ai-catalog.json. A client fetches the catalog, then each card, and knows where to connect
without being configured by hand.
This package does both halves: it builds, validates and serves cards and catalogs, and it discovers them from a client. On a LAN it also advertises and finds hosts over mDNS. Cards and catalogs are public and unauthenticated, so what to serve and what to connect to stay your decision.
Install
npm install @cubicecho/mcp-discovery zod
npm install bonjour-service # only for mDNSNode 22 or later, ESM only.
Quick start: be found on the LAN
Save this as server.mjs and run node server.mjs. It serves a catalog and a card, announces itself over
mDNS, then finds the server it just announced, as another machine on the network would:
import { createServer } from 'node:http';
import { hostname } from 'node:os';
import { airIdentifier, createServerCard, discoveryMiddleware, hostSlug } from '@cubicecho/mcp-discovery';
import { advertise, watchServers } from '@cubicecho/mcp-discovery/mdns';
const port = 3000;
const instance = hostSlug(hostname());
// Serves /.well-known/ai-catalog.json and /mcp/server-card. Your own MCP endpoint goes at /mcp.
const discovery = discoveryMiddleware(() => [
{
path: '/mcp',
identifier: airIdentifier(`${instance}.skills`, 'skills'),
card: ({ endpointUrl }) =>
createServerCard({
name: `com.example.skills.${instance}/skills`,
version: '1.0.0',
description: 'Skills for agents.',
remotes: [{ type: 'streamable-http', url: endpointUrl }],
}),
},
]);
const server = createServer((request, response) => {
discovery(request, response, (error) => response.writeHead(error ? 500 : 404).end());
});
server.listen(port, '0.0.0.0', async () => {
const advertisement = await advertise({ name: `Skills on ${instance}`, port });
// Usually in another process, such as a router that links the servers it finds.
const watch = await watchServers({
onUp: ({ key, connection }) => console.log('found', key, connection?.url),
onDown: ({ key }) => console.log('gone', key),
});
process.once('SIGINT', async () => {
await watch.stop();
await advertisement.stop();
process.exit(0);
});
});Documentation
- Install and entry points
- Server cards
- AI catalogs
- Serving, with Express or plain
node:http - Discovering the servers on a known host
- mDNS: advertising and finding hosts
- Watching servers on the LAN
- Beside graphql-mdns-discovery
- Common mistakes
- Every export, as
llms.txt - Design decisions
- Changelog
