MCPcopy Create free account
hub / github.com/cloudflare/mcp / processSpec

Function processSpec

src/spec-processor.ts:62–93  ·  view source on GitHub ↗
(spec: Record<string, unknown>)

Source from the content-addressed store, hash-verified

60 * Resolves all $refs inline and extracts only the fields needed for search.
61 */
62export function processSpec(spec: Record<string, unknown>): {
63 paths: Record<string, Record<string, unknown>>
64} {
65 const rawPaths = (spec.paths || {}) as Record<string, Record<string, OperationObject>>
66 const paths: Record<string, Record<string, unknown>> = {}
67
68 for (const [path, pathItem] of Object.entries(rawPaths)) {
69 if (!pathItem) continue
70 paths[path] = {}
71
72 for (const method of HTTP_METHODS) {
73 const op = pathItem[method]
74 if (op) {
75 const product = extractProduct(path)
76 const tags = op.tags ? [...op.tags] : []
77 if (product && !tags.some((t) => t.toLowerCase() === product.toLowerCase())) {
78 tags.unshift(product)
79 }
80 paths[path][method] = {
81 summary: op.summary,
82 description: op.description,
83 tags,
84 parameters: resolveRefs(op.parameters, spec),
85 requestBody: resolveRefs(op.requestBody, spec),
86 responses: resolveRefs(op.responses, spec)
87 }
88 }
89 }
90 }
91
92 return { paths }
93}
94
95/**
96 * Extract sorted product list from the spec paths.

Callers 3

scheduledFunction · 0.90
seed-r2.tsFile · 0.90

Calls 2

extractProductFunction · 0.85
resolveRefsFunction · 0.85

Tested by

no test coverage detected