Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

discovery.ts

85 lines2.4 KB

1/**
2 * Agent-discovery documents (PLAN.md task 10.3): the RFC 9727 api-catalog
3 * linkset, the SEP-1649 MCP server card, and the Agent Skills Discovery
4 * index. All derive from the same sources as the surfaces they point at
5 * (openapi.json version, MCP TOOLS, live SKILL.md) so they can't drift.
6 */
7import { TOOLS } from '#/server/mcp.ts'
8import { skillMd } from '#/server/skill.ts'
9​
10export const LINKSET_CONTENT_TYPE = 'application/linkset+json'
11​
12export function apiCatalog(origin: string): Record<string, unknown> {
13 return {
14 linkset: [
15 {
16 anchor: `${origin}/v1`,
17 'service-desc': [
18 { href: `${origin}/openapi.json`, type: 'application/json' },
19 ],
20 'service-doc': [
21 { href: `${origin}/docs`, type: 'text/html' },
22 { href: `${origin}/llms.txt`, type: 'text/markdown' },
23 ],
24 status: [{ href: `${origin}/v1`, type: 'application/json' }],
25 },
26 ],
27 }
29​
30export function mcpServerCard(origin: string): Record<string, unknown> {
31 return {
32 serverInfo: {
33 name: 'modelschemas',
34 title: 'modelschemas — live AI model schemas',
35 version: '0.1.0',
36 },
37 description:
38 'Live AI model schema service: which models exist right now, their ' +
39 'metadata, and per-endpoint request/response JSON Schemas for every ' +
40 'monitored provider.',
41 transport: {
42 type: 'streamable-http',
43 endpoint: `${origin}/mcp`,
44 },
45 capabilities: { tools: {} },
46 tools: TOOLS.map((tool) => ({
47 name: tool.name,
48 description: tool.description,
49 })),
50 documentation: `${origin}/docs`,
51 }
53​
54function skillDescription(): string {
55 const match = /^description: (.+)$/m.exec(skillMd)
56 return match?.[1] ?? 'Live AI model schema service.'
58​
59export async function skillSha256(): Promise<string> {
60 const digest = await crypto.subtle.digest(
61 'SHA-256',
62 new TextEncoder().encode(skillMd),
63 )
64 return [...new Uint8Array(digest)]
65 .map((byte) => byte.toString(16).padStart(2, '0'))
66 .join('')
68​
69export async function agentSkillsIndex(
70 origin: string,
71): Promise<Record<string, unknown>> {
72 return {
73 $schema:
74 'https://raw.githubusercontent.com/agent-skills/discovery/v0.2.0/index.schema.json',
75 skills: [
76 {
77 name: 'modelschemas',
78 type: 'skill',
79 description: skillDescription(),
80 url: `${origin}/skill`,
81 sha256: await skillSha256(),
82 },
83 ],
84 }