@runcontext/mcp 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +386 -354
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -54
- package/dist/index.d.ts +75 -54
- package/dist/index.mjs +398 -366
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -10
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/erickittelson/Desktop/ContextKit/packages/mcp/dist/index.cjs","../src/server.ts","../src/resources/manifest.ts","../src/resources/concept.ts","../src/resources/product.ts","../src/resources/policy.ts","../src/resources/glossary.ts","../src/tools/search.ts","../src/tools/explain.ts","../src/tools/validate.ts","../src/index.ts"],"names":[],"mappings":"AAAA;ACAA,gEAA4C;AAC5C,0BAAkB;ADElB;AACA;AEEO,SAAS,YAAA,CAAa,QAAA,EAAwC;AACnE,EAAA,OAAO;AAAA,IACL,QAAA,EAAU;AAAA,MACR;AAAA,QACE,GAAA,EAAK,oBAAA;AAAA,QACL,QAAA,EAAU,kBAAA;AAAA,QACV,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,QAAA,EAAU,IAAA,EAAM,CAAC;AAAA,MACxC;AAAA,IACF;AAAA,EACF,CAAA;AACF;AFAA;AACA;AGXO,SAAS,WAAA,CAAY,QAAA,EAAoB,EAAA,EAAgC;AAC9E,EAAA,MAAM,QAAA,EAAuC,QAAA,CAAS,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,GAAA,IAAO,EAAE,CAAA;AACtF,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO;AAAA,MACL,QAAA,EAAU;AAAA,QACR;AAAA,UACE,GAAA,EAAK,CAAA,kBAAA,EAAqB,EAAE,CAAA,CAAA;AAClB,UAAA;AACa,UAAA;AACzB,QAAA;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AA;AACc,MAAA;AAClC,IAAA;AACc,IAAA;AACiB,IAAA;AAClC,EAAA;AAGO,EAAA;AACL,IAAA;AACqB,IAAA;AACc,MAAA;AAClC,IAAA;AACc,IAAA;AACiB,IAAA;AAClC,EAAA;AAGO,EAAA;AACL,IAAA;AACqB,IAAA;AACc,MAAA;AAClC,IAAA;AACc,IAAA;AACgB,IAAA;AACjC,EAAA;AAKO,EAAA;AACL,IAAA;AACA,IAAA;AAC6B,IAAA;AACA,IAAA;AAC/B,EAAA;AAGO,EAAA;AACL,IAAA;AACA,IAAA;AAC0B,IAAA;AACQ,IAAA;AACpC,EAAA;AAGO,EAAA;AACL,IAAA;AACA,IAAA;AACiC,IAAA;AACV,IAAA;AACzB,EAAA;AAEO,EAAA;AACT;ADySuC;AACA;AUrZZ;AVuZY;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erickittelson/Desktop/ContextKit/packages/mcp/dist/index.cjs","sourcesContent":[null,"import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { Manifest } from '@runcontext/core';\n\nimport { readManifest } from './resources/manifest.js';\nimport { readConcept, listConcepts } from './resources/concept.js';\nimport { readProduct, listProducts } from './resources/product.js';\nimport { readPolicy, listPolicies } from './resources/policy.js';\nimport { readGlossary } from './resources/glossary.js';\nimport { searchContext } from './tools/search.js';\nimport { explainNode } from './tools/explain.js';\nimport { validateContext } from './tools/validate.js';\n\n/**\n * Creates an MCP server wired up with all ContextKit resources and tools.\n */\nexport function createContextMcpServer(manifest: Manifest): McpServer {\n const server = new McpServer(\n {\n name: 'contextkit',\n version: '0.1.0',\n },\n {\n capabilities: {\n resources: {},\n tools: {},\n },\n },\n );\n\n // ── Static Resources ──────────────────────────────────────────────\n\n // context://manifest — full manifest\n server.resource(\n 'manifest',\n 'context://manifest',\n { description: 'The full ContextKit manifest', mimeType: 'application/json' },\n () => readManifest(manifest),\n );\n\n // context://glossary — all terms\n server.resource(\n 'glossary',\n 'context://glossary',\n { description: 'Glossary of all terms', mimeType: 'application/json' },\n () => readGlossary(manifest),\n );\n\n // ── Template Resources ────────────────────────────────────────────\n\n // context://concept/{id}\n server.resource(\n 'concept',\n new ResourceTemplate('context://concept/{id}', {\n list: () => listConcepts(manifest),\n }),\n { description: 'A single concept by ID', mimeType: 'application/json' },\n (uri, variables) => readConcept(manifest, String(variables.id)),\n );\n\n // context://product/{id}\n server.resource(\n 'product',\n new ResourceTemplate('context://product/{id}', {\n list: () => listProducts(manifest),\n }),\n { description: 'A single product by ID', mimeType: 'application/json' },\n (uri, variables) => readProduct(manifest, String(variables.id)),\n );\n\n // context://policy/{id}\n server.resource(\n 'policy',\n new ResourceTemplate('context://policy/{id}', {\n list: () => listPolicies(manifest),\n }),\n { description: 'A single policy by ID', mimeType: 'application/json' },\n (uri, variables) => readPolicy(manifest, String(variables.id)),\n );\n\n // ── Tools ─────────────────────────────────────────────────────────\n\n // context_search — search across all nodes\n server.tool(\n 'context_search',\n 'Search across all concepts, products, policies, entities, and terms',\n { query: z.string().describe('The search query (case-insensitive substring match)') },\n ({ query }) => searchContext(manifest, query),\n );\n\n // context_explain — explain a node by ID\n server.tool(\n 'context_explain',\n 'Get comprehensive info about a node: the node itself, dependencies, dependents, applicable policies, and owner',\n { id: z.string().describe('The ID of the node to explain') },\n ({ id }) => explainNode(manifest, id),\n );\n\n // context_validate — run compile + lint\n server.tool(\n 'context_validate',\n 'Run compile and lint validation on the context directory and return diagnostics',\n { rootDir: z.string().optional().describe('Root directory to validate (defaults to cwd)') },\n async ({ rootDir }) => validateContext(rootDir),\n );\n\n return server;\n}\n","import type { Manifest } from '@runcontext/core';\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Returns the full manifest as a JSON resource.\n */\nexport function readManifest(manifest: Manifest): ReadResourceResult {\n return {\n contents: [\n {\n uri: 'context://manifest',\n mimeType: 'application/json',\n text: JSON.stringify(manifest, null, 2),\n },\n ],\n };\n}\n","import type { Manifest, ManifestConcept } from '@runcontext/core';\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Returns a single concept by ID from the manifest.\n */\nexport function readConcept(manifest: Manifest, id: string): ReadResourceResult {\n const concept: ManifestConcept | undefined = manifest.concepts.find((c) => c.id === id);\n if (!concept) {\n return {\n contents: [\n {\n uri: `context://concept/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify({ error: `Concept not found: ${id}` }),\n },\n ],\n };\n }\n return {\n contents: [\n {\n uri: `context://concept/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify(concept, null, 2),\n },\n ],\n };\n}\n\n/**\n * Lists all concepts as resources.\n */\nexport function listConcepts(manifest: Manifest) {\n return {\n resources: manifest.concepts.map((c) => ({\n uri: `context://concept/${c.id}`,\n name: c.id,\n description: c.definition,\n mimeType: 'application/json' as const,\n })),\n };\n}\n","import type { Manifest, ManifestProduct } from '@runcontext/core';\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Returns a single product by ID from the manifest.\n */\nexport function readProduct(manifest: Manifest, id: string): ReadResourceResult {\n const product: ManifestProduct | undefined = manifest.products.find((p) => p.id === id);\n if (!product) {\n return {\n contents: [\n {\n uri: `context://product/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify({ error: `Product not found: ${id}` }),\n },\n ],\n };\n }\n return {\n contents: [\n {\n uri: `context://product/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify(product, null, 2),\n },\n ],\n };\n}\n\n/**\n * Lists all products as resources.\n */\nexport function listProducts(manifest: Manifest) {\n return {\n resources: manifest.products.map((p) => ({\n uri: `context://product/${p.id}`,\n name: p.id,\n description: p.description,\n mimeType: 'application/json' as const,\n })),\n };\n}\n","import type { Manifest, ManifestPolicy } from '@runcontext/core';\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Returns a single policy by ID from the manifest.\n */\nexport function readPolicy(manifest: Manifest, id: string): ReadResourceResult {\n const policy: ManifestPolicy | undefined = manifest.policies.find((p) => p.id === id);\n if (!policy) {\n return {\n contents: [\n {\n uri: `context://policy/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify({ error: `Policy not found: ${id}` }),\n },\n ],\n };\n }\n return {\n contents: [\n {\n uri: `context://policy/${id}`,\n mimeType: 'application/json',\n text: JSON.stringify(policy, null, 2),\n },\n ],\n };\n}\n\n/**\n * Lists all policies as resources.\n */\nexport function listPolicies(manifest: Manifest) {\n return {\n resources: manifest.policies.map((p) => ({\n uri: `context://policy/${p.id}`,\n name: p.id,\n description: p.description,\n mimeType: 'application/json' as const,\n })),\n };\n}\n","import type { Manifest } from '@runcontext/core';\nimport type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Returns all terms as a glossary JSON resource.\n */\nexport function readGlossary(manifest: Manifest): ReadResourceResult {\n const glossary = manifest.terms.map((t) => ({\n id: t.id,\n definition: t.definition,\n synonyms: t.synonyms ?? [],\n mapsTo: t.mapsTo ?? [],\n }));\n\n return {\n contents: [\n {\n uri: 'context://glossary',\n mimeType: 'application/json',\n text: JSON.stringify(glossary, null, 2),\n },\n ],\n };\n}\n","import type { Manifest } from '@runcontext/core';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\n\ninterface SearchableItem {\n kind: string;\n id: string;\n definition?: string;\n description?: string;\n tags?: string[];\n}\n\n/**\n * Searches across all concepts, products, policies, entities, and terms\n * in the manifest. Matches case-insensitively on id, definition/description,\n * and tags.\n */\nexport function searchContext(manifest: Manifest, query: string): CallToolResult {\n const q = query.toLowerCase();\n\n const items: SearchableItem[] = [\n ...manifest.concepts.map((c) => ({\n kind: 'concept' as const,\n id: c.id,\n definition: c.definition,\n tags: c.tags,\n })),\n ...manifest.products.map((p) => ({\n kind: 'product' as const,\n id: p.id,\n description: p.description,\n tags: p.tags,\n })),\n ...manifest.policies.map((p) => ({\n kind: 'policy' as const,\n id: p.id,\n description: p.description,\n tags: p.tags,\n })),\n ...manifest.entities.map((e) => ({\n kind: 'entity' as const,\n id: e.id,\n definition: e.definition,\n tags: e.tags,\n })),\n ...manifest.terms.map((t) => ({\n kind: 'term' as const,\n id: t.id,\n definition: t.definition,\n tags: t.tags,\n })),\n ];\n\n const matches = items.filter((item) => {\n if (item.id.toLowerCase().includes(q)) return true;\n if (item.definition && item.definition.toLowerCase().includes(q)) return true;\n if (item.description && item.description.toLowerCase().includes(q)) return true;\n if (item.tags && item.tags.some((tag) => tag.toLowerCase().includes(q))) return true;\n return false;\n });\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({ query, resultCount: matches.length, results: matches }, null, 2),\n },\n ],\n };\n}\n","import type { Manifest } from '@runcontext/core';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Finds a node by ID in the manifest and returns comprehensive info:\n * the node itself, its dependencies, dependents, applicable policies,\n * and owner info.\n */\nexport function explainNode(manifest: Manifest, id: string): CallToolResult {\n const index = manifest.indexes.byId[id];\n if (!index) {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({ error: `Node not found: ${id}` }, null, 2),\n },\n ],\n };\n }\n\n // Retrieve the node from the appropriate collection\n let node: Record<string, unknown> | undefined;\n switch (index.kind) {\n case 'concept':\n node = manifest.concepts[index.index] as unknown as Record<string, unknown>;\n break;\n case 'product':\n node = manifest.products[index.index] as unknown as Record<string, unknown>;\n break;\n case 'policy':\n node = manifest.policies[index.index] as unknown as Record<string, unknown>;\n break;\n case 'entity':\n node = manifest.entities[index.index] as unknown as Record<string, unknown>;\n break;\n case 'term':\n node = manifest.terms[index.index] as unknown as Record<string, unknown>;\n break;\n case 'owner':\n node = manifest.owners[index.index] as unknown as Record<string, unknown>;\n break;\n }\n\n if (!node) {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({ error: `Node data not found for: ${id}` }, null, 2),\n },\n ],\n };\n }\n\n // Find dependencies (concepts that this node dependsOn)\n const dependencies: Array<{ id: string; kind: string }> = [];\n const dependsOn = (node as { dependsOn?: string[] }).dependsOn;\n if (dependsOn) {\n for (const depId of dependsOn) {\n const depIndex = manifest.indexes.byId[depId];\n if (depIndex) {\n dependencies.push({ id: depId, kind: depIndex.kind });\n }\n }\n }\n\n // Find dependents (concepts that depend on this node)\n const dependents: Array<{ id: string; kind: string }> = [];\n for (const concept of manifest.concepts) {\n if (concept.dependsOn?.includes(id)) {\n dependents.push({ id: concept.id, kind: 'concept' });\n }\n }\n\n // Find applicable policies (policies whose rules reference this node's tags or ID)\n const applicablePolicies: Array<{ id: string; description: string }> = [];\n const nodeTags = (node as { tags?: string[] }).tags ?? [];\n for (const policy of manifest.policies) {\n const applies = policy.rules.some((rule) => {\n if (rule.when.conceptIds?.includes(id)) return true;\n if (rule.when.tagsAny?.some((tag) => nodeTags.includes(tag))) return true;\n return false;\n });\n if (applies) {\n applicablePolicies.push({ id: policy.id, description: policy.description });\n }\n }\n\n // Find owner info\n let ownerInfo: Record<string, unknown> | undefined;\n const ownerId = (node as { owner?: string }).owner;\n if (ownerId) {\n ownerInfo = manifest.owners.find((o) => o.id === ownerId) as unknown as Record<string, unknown>;\n }\n\n const result = {\n kind: index.kind,\n node,\n dependencies,\n dependents,\n applicablePolicies,\n owner: ownerInfo ?? null,\n };\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(result, null, 2),\n },\n ],\n };\n}\n","import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Runs the compile + lint pipeline on a context directory and returns diagnostics.\n */\nexport async function validateContext(rootDir?: string): Promise<CallToolResult> {\n try {\n // Dynamic import to avoid circular dependency issues at load time\n const { compile, LintEngine, ALL_RULES } = await import('@runcontext/core');\n\n const contextDir = rootDir ?? process.cwd();\n\n // Run the compiler pipeline\n const compileResult = await compile({\n contextDir,\n config: {},\n });\n\n // Run the linter\n const engine = new LintEngine();\n for (const rule of ALL_RULES) {\n engine.register(rule);\n }\n const lintDiagnostics = engine.run(compileResult.graph);\n\n // Combine diagnostics\n const allDiagnostics = [...compileResult.diagnostics, ...lintDiagnostics];\n\n const summary = {\n contextDir,\n compileDiagnostics: compileResult.diagnostics.length,\n lintDiagnostics: lintDiagnostics.length,\n totalDiagnostics: allDiagnostics.length,\n errors: allDiagnostics.filter((d) => d.severity === 'error').length,\n warnings: allDiagnostics.filter((d) => d.severity === 'warning').length,\n diagnostics: allDiagnostics,\n };\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(summary, null, 2),\n },\n ],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify({ error: `Validation failed: ${message}` }, null, 2),\n },\n ],\n isError: true,\n };\n }\n}\n","export const MCP_VERSION = '0.1.0';\n\nexport { createContextMcpServer } from './server.js';\n\n// Re-export resource handlers for direct testing / reuse\nexport { readManifest } from './resources/manifest.js';\nexport { readConcept, listConcepts } from './resources/concept.js';\nexport { readProduct, listProducts } from './resources/product.js';\nexport { readPolicy, listPolicies } from './resources/policy.js';\nexport { readGlossary } from './resources/glossary.js';\n\n// Re-export tool handlers for direct testing / reuse\nexport { searchContext } from './tools/search.js';\nexport { explainNode } from './tools/explain.js';\nexport { validateContext } from './tools/validate.js';\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/erickittelson/Desktop/ContextKit/packages/mcp/dist/index.cjs","../src/server.ts","../src/resources/manifest.ts","../src/resources/model.ts","../src/resources/glossary.ts","../src/resources/tier.ts","../src/tools/search.ts","../src/tools/explain.ts","../src/tools/validate.ts","../src/tools/tier.ts","../src/tools/golden-query.ts","../src/tools/guardrails.ts"],"names":["ResourceTemplate"],"mappings":"AAAA;ACAA,gEAA0B;AAC1B,oEAAqC;AAErC,wCAAkD;ADClD;AACA;AEEO,SAAS,wBAAA,CAAyB,MAAA,EAAmB,QAAA,EAA0B;AACpF,EAAA,MAAA,CAAO,QAAA;AAAA,IACL,UAAA;AAAA,IACA,oBAAA;AA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;AAEO,EAAA;AACT;AAMuC;AAC9B,EAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AAC8B,MAAA;AAC9B,IAAA;AACsB,IAAA;AACW,MAAA;AACxB,MAAA;AACI,QAAA;AACP,UAAA;AACQ,YAAA;AACe,YAAA;AACvB,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AACF,EAAA;AACF;AX0VuC;AACA;ACpY0C;AAClD,EAAA;AACrB,IAAA;AACG,IAAA;AACV,EAAA;AAGgC,EAAA;AACH,EAAA;AACG,EAAA;AACI,EAAA;AAGF,EAAA;AACC,EAAA;AACF,EAAA;AACJ,EAAA;AACE,EAAA;AACD,EAAA;AAExB,EAAA;AACT;AAUuB;AACe,EAAA;AACH,EAAA;AACL,EAAA;AAEM,EAAA;AACG,EAAA;AACT,EAAA;AAEN,EAAA;AACQ,EAAA;AAEvB,EAAA;AACT;ADqXuC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erickittelson/Desktop/ContextKit/packages/mcp/dist/index.cjs","sourcesContent":[null,"import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport type { Manifest, ContextGraph, ContextKitConfig } from '@runcontext/core';\nimport { compile, emitManifest, loadConfig } from '@runcontext/core';\n\nimport { registerManifestResource } from './resources/manifest.js';\nimport { registerModelResource } from './resources/model.js';\nimport { registerGlossaryResource } from './resources/glossary.js';\nimport { registerTierResource } from './resources/tier.js';\n\nimport { registerSearchTool } from './tools/search.js';\nimport { registerExplainTool } from './tools/explain.js';\nimport { registerValidateTool } from './tools/validate.js';\nimport { registerTierTool } from './tools/tier.js';\nimport { registerGoldenQueryTool } from './tools/golden-query.js';\nimport { registerGuardrailsTool } from './tools/guardrails.js';\n\n/**\n * Create and configure an MCP server with all ContextKit resources and tools.\n *\n * Use this for testing or embedding — no transport is connected.\n */\nexport function createServer(manifest: Manifest, graph: ContextGraph): McpServer {\n const server = new McpServer({\n name: 'contextkit',\n version: '0.2.0',\n });\n\n // Register resources (4)\n registerManifestResource(server, manifest);\n registerModelResource(server, manifest);\n registerGlossaryResource(server, manifest);\n registerTierResource(server, manifest);\n\n // Register tools (6)\n registerSearchTool(server, manifest);\n registerExplainTool(server, manifest);\n registerValidateTool(server, graph);\n registerTierTool(server, graph);\n registerGoldenQueryTool(server, manifest);\n registerGuardrailsTool(server, manifest);\n\n return server;\n}\n\n/**\n * Compile context, create server, and connect stdio transport.\n *\n * This is the main entry point for running the MCP server as a process.\n */\nexport async function startServer(options?: {\n contextDir?: string;\n rootDir?: string;\n}): Promise<McpServer> {\n const rootDir = options?.rootDir ?? process.cwd();\n const config = loadConfig(rootDir);\n const contextDir = options?.contextDir ?? config.context_dir;\n\n const { graph } = await compile({ contextDir, config });\n const manifest = emitManifest(graph, config);\n const server = createServer(manifest, graph);\n\n const transport = new StdioServerTransport();\n await server.connect(transport);\n\n return server;\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { Manifest } from '@runcontext/core';\n\n/**\n * Register the `context://manifest` resource.\n * Returns the full compiled manifest as JSON.\n */\nexport function registerManifestResource(server: McpServer, manifest: Manifest): void {\n server.resource(\n 'manifest',\n 'context://manifest',\n { description: 'Full ContextKit manifest JSON (models, governance, rules, lineage, terms, owners, tiers)' },\n async (uri) => ({\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify(manifest, null, 2),\n },\n ],\n }),\n );\n}\n","import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { Manifest } from '@runcontext/core';\n\n/**\n * Build a merged view of a model: OSI model + governance + rules + lineage + tier.\n */\nexport function buildModelView(name: string, manifest: Manifest): Record<string, unknown> | null {\n const model = manifest.models[name];\n if (!model) return null;\n\n return {\n model,\n governance: manifest.governance[name] ?? null,\n rules: manifest.rules[name] ?? null,\n lineage: manifest.lineage[name] ?? null,\n tier: manifest.tiers[name] ?? null,\n };\n}\n\n/**\n * Register the `context://model/{name}` resource template.\n * Returns the OSI model merged with governance, rules, lineage, and tier data.\n */\nexport function registerModelResource(server: McpServer, manifest: Manifest): void {\n server.resource(\n 'model',\n new ResourceTemplate('context://model/{name}', {\n list: async () => ({\n resources: Object.keys(manifest.models).map((name) => ({\n uri: `context://model/${name}`,\n name,\n description: manifest.models[name]?.description ?? `Model: ${name}`,\n })),\n }),\n }),\n { description: 'OSI semantic model merged with governance, rules, lineage, and tier' },\n async (uri, { name }) => {\n const modelName = String(name);\n const view = buildModelView(modelName, manifest);\n if (!view) {\n throw new Error(`Model '${modelName}' not found`);\n }\n return {\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify(view, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { Manifest } from '@runcontext/core';\n\n/**\n * Register the `context://glossary` resource.\n * Returns all glossary terms as JSON.\n */\nexport function registerGlossaryResource(server: McpServer, manifest: Manifest): void {\n server.resource(\n 'glossary',\n 'context://glossary',\n { description: 'All ContextKit glossary terms with definitions, synonyms, and mappings' },\n async (uri) => ({\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify(manifest.terms, null, 2),\n },\n ],\n }),\n );\n}\n","import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { Manifest } from '@runcontext/core';\n\n/**\n * Register the `context://tier/{name}` resource template.\n * Returns the tier scorecard for a specific model.\n */\nexport function registerTierResource(server: McpServer, manifest: Manifest): void {\n server.resource(\n 'tier',\n new ResourceTemplate('context://tier/{name}', {\n list: async () => ({\n resources: Object.keys(manifest.tiers).map((name) => ({\n uri: `context://tier/${name}`,\n name,\n description: `Tier scorecard for model: ${name} (${manifest.tiers[name]?.tier ?? 'unknown'})`,\n })),\n }),\n }),\n { description: 'Tier scorecard for a model (bronze/silver/gold checks and results)' },\n async (uri, { name }) => {\n const modelName = String(name);\n const tier = manifest.tiers[modelName];\n if (!tier) {\n throw new Error(`Tier data for model '${modelName}' not found`);\n }\n return {\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify(tier, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { Manifest } from '@runcontext/core';\n\nexport interface SearchResult {\n type: 'model' | 'dataset' | 'field' | 'term' | 'owner';\n name: string;\n description?: string;\n model?: string;\n dataset?: string;\n}\n\n/**\n * Perform keyword search across all node types in the manifest.\n */\nexport function searchManifest(manifest: Manifest, query: string): SearchResult[] {\n const results: SearchResult[] = [];\n const q = query.toLowerCase();\n\n // Search models\n for (const [name, model] of Object.entries(manifest.models)) {\n if (\n name.toLowerCase().includes(q) ||\n model.description?.toLowerCase().includes(q)\n ) {\n results.push({\n type: 'model',\n name,\n description: model.description,\n });\n }\n\n // Search datasets\n for (const ds of model.datasets ?? []) {\n if (\n ds.name.toLowerCase().includes(q) ||\n ds.description?.toLowerCase().includes(q)\n ) {\n results.push({\n type: 'dataset',\n name: ds.name,\n description: ds.description,\n model: name,\n });\n }\n\n // Search fields\n if (ds.fields) {\n for (const field of ds.fields) {\n if (\n field.name.toLowerCase().includes(q) ||\n field.description?.toLowerCase().includes(q) ||\n field.label?.toLowerCase().includes(q)\n ) {\n results.push({\n type: 'field',\n name: field.name,\n description: field.description,\n model: name,\n dataset: ds.name,\n });\n }\n }\n }\n }\n }\n\n // Search terms\n for (const [id, term] of Object.entries(manifest.terms)) {\n if (\n id.toLowerCase().includes(q) ||\n term.definition.toLowerCase().includes(q) ||\n term.synonyms?.some((s) => s.toLowerCase().includes(q))\n ) {\n results.push({\n type: 'term',\n name: id,\n description: term.definition,\n });\n }\n }\n\n // Search owners\n for (const [id, owner] of Object.entries(manifest.owners)) {\n if (\n id.toLowerCase().includes(q) ||\n owner.display_name.toLowerCase().includes(q) ||\n owner.description?.toLowerCase().includes(q)\n ) {\n results.push({\n type: 'owner',\n name: id,\n description: owner.display_name,\n });\n }\n }\n\n return results;\n}\n\n/**\n * Register the `context_search` tool.\n * Keyword search across all node types (models, datasets, fields, terms, owners).\n */\nexport function registerSearchTool(server: McpServer, manifest: Manifest): void {\n server.tool(\n 'context_search',\n 'Search across all ContextKit nodes (models, datasets, fields, terms, owners) by keyword',\n { query: z.string().describe('Keyword to search for') },\n async ({ query }) => {\n const results = searchManifest(manifest, query);\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(results, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { Manifest } from '@runcontext/core';\n\nexport interface ExplainResult {\n model: Record<string, unknown>;\n governance: Record<string, unknown> | null;\n rules: Record<string, unknown> | null;\n lineage: Record<string, unknown> | null;\n tier: Record<string, unknown> | null;\n owner: Record<string, unknown> | null;\n relatedTerms: Record<string, unknown>[];\n}\n\n/**\n * Deep lookup for a model with all related governance context.\n */\nexport function explainModel(name: string, manifest: Manifest): ExplainResult | null {\n const model = manifest.models[name];\n if (!model) return null;\n\n const governance = manifest.governance[name] ?? null;\n const rules = manifest.rules[name] ?? null;\n const lineage = manifest.lineage[name] ?? null;\n const tier = manifest.tiers[name] ?? null;\n\n // Find the owner\n const ownerKey = governance?.owner;\n const owner = ownerKey ? (manifest.owners[ownerKey] ?? null) : null;\n\n // Find related glossary terms — terms whose tags overlap with model tags\n const modelTags = governance?.tags ?? [];\n const relatedTerms: Record<string, unknown>[] = [];\n for (const [, term] of Object.entries(manifest.terms)) {\n const termTags = term.tags ?? [];\n const hasOverlap = modelTags.some((t) => termTags.includes(t));\n const mapsToModel = term.maps_to?.some((m) => m === name);\n if (hasOverlap || mapsToModel) {\n relatedTerms.push(term as unknown as Record<string, unknown>);\n }\n }\n\n return {\n model: model as unknown as Record<string, unknown>,\n governance: governance as unknown as Record<string, unknown> | null,\n rules: rules as unknown as Record<string, unknown> | null,\n lineage: lineage as unknown as Record<string, unknown> | null,\n tier: tier as unknown as Record<string, unknown> | null,\n owner: owner as unknown as Record<string, unknown> | null,\n relatedTerms,\n };\n}\n\n/**\n * Register the `context_explain` tool.\n * Deep lookup with related governance for a model.\n */\nexport function registerExplainTool(server: McpServer, manifest: Manifest): void {\n server.tool(\n 'context_explain',\n 'Deep lookup of a model with all related governance, rules, lineage, tier, owner, and glossary terms',\n { model: z.string().describe('Name of the model to explain') },\n async ({ model }) => {\n const result = explainModel(model, manifest);\n if (!result) {\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify({ error: `Model '${model}' not found` }),\n },\n ],\n };\n }\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { ContextGraph, Diagnostic } from '@runcontext/core';\nimport { LintEngine, ALL_RULES } from '@runcontext/core';\n\nexport interface ValidateResult {\n totalDiagnostics: number;\n errors: number;\n warnings: number;\n diagnostics: Diagnostic[];\n}\n\n/**\n * Run the full linter against the context graph.\n */\nexport function validateGraph(graph: ContextGraph): ValidateResult {\n const engine = new LintEngine();\n for (const rule of ALL_RULES) {\n engine.register(rule);\n }\n\n const diagnostics = engine.run(graph);\n const errors = diagnostics.filter((d) => d.severity === 'error').length;\n const warnings = diagnostics.filter((d) => d.severity === 'warning').length;\n\n return {\n totalDiagnostics: diagnostics.length,\n errors,\n warnings,\n diagnostics,\n };\n}\n\n/**\n * Register the `context_validate` tool.\n * Runs the linter and returns diagnostics.\n */\nexport function registerValidateTool(server: McpServer, graph: ContextGraph): void {\n server.tool(\n 'context_validate',\n 'Run ContextKit linter against the context graph and return diagnostics',\n {},\n async () => {\n const result = validateGraph(graph);\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { ContextGraph, TierScore } from '@runcontext/core';\nimport { computeTier } from '@runcontext/core';\n\n/**\n * Compute the tier for a model from the context graph.\n */\nexport function computeModelTier(modelName: string, graph: ContextGraph): TierScore | null {\n if (!graph.models.has(modelName)) return null;\n return computeTier(modelName, graph);\n}\n\n/**\n * Register the `context_tier` tool.\n * Computes the tier scorecard for a specified model.\n */\nexport function registerTierTool(server: McpServer, graph: ContextGraph): void {\n server.tool(\n 'context_tier',\n 'Compute the metadata tier (none/bronze/silver/gold) for a model with detailed check results',\n { model: z.string().describe('Name of the model to tier') },\n async ({ model }) => {\n const result = computeModelTier(model, graph);\n if (!result) {\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify({ error: `Model '${model}' not found` }),\n },\n ],\n };\n }\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { Manifest, GoldenQuery } from '@runcontext/core';\n\nexport interface GoldenQueryMatch {\n model: string;\n query: GoldenQuery;\n score: number;\n}\n\n/**\n * Find golden queries matching a natural-language question.\n * Uses simple keyword overlap scoring.\n */\nexport function findGoldenQueries(manifest: Manifest, question: string): GoldenQueryMatch[] {\n const stopWords = new Set(['a', 'an', 'the', 'is', 'in', 'on', 'at', 'to', 'of', 'for', 'and', 'or', 'not']);\n const qWords = question.toLowerCase().split(/\\s+/).filter((w) => w.length > 0 && !stopWords.has(w));\n const matches: GoldenQueryMatch[] = [];\n\n for (const [modelName, rules] of Object.entries(manifest.rules)) {\n if (!rules.golden_queries) continue;\n\n for (const gq of rules.golden_queries) {\n const gqWords = gq.question.toLowerCase().split(/\\s+/);\n const overlap = qWords.filter((w) => gqWords.some((gw) => gw.includes(w))).length;\n if (overlap > 0) {\n matches.push({\n model: modelName,\n query: gq,\n score: overlap / Math.max(qWords.length, 1),\n });\n }\n }\n }\n\n // Sort by score descending\n matches.sort((a, b) => b.score - a.score);\n return matches;\n}\n\n/**\n * Register the `context_golden_query` tool.\n * Finds golden queries matching a given question.\n */\nexport function registerGoldenQueryTool(server: McpServer, manifest: Manifest): void {\n server.tool(\n 'context_golden_query',\n 'Find golden SQL queries that match a natural-language question',\n { question: z.string().describe('Natural-language question to match against golden queries') },\n async ({ question }) => {\n const results = findGoldenQueries(manifest, question);\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(results, null, 2),\n },\n ],\n };\n },\n );\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport type { Manifest, GuardrailFilter } from '@runcontext/core';\n\nexport interface GuardrailMatch {\n model: string;\n filter: GuardrailFilter;\n}\n\n/**\n * Find guardrail filters that apply to the given tables.\n */\nexport function findGuardrails(manifest: Manifest, tables: string[]): GuardrailMatch[] {\n const matches: GuardrailMatch[] = [];\n const tableSet = new Set(tables.map((t) => t.toLowerCase()));\n\n for (const [modelName, rules] of Object.entries(manifest.rules)) {\n if (!rules.guardrail_filters) continue;\n\n for (const gf of rules.guardrail_filters) {\n // A guardrail matches if:\n // 1. It has no tables restriction (applies globally), or\n // 2. Any of its tables match the requested tables\n const applies =\n !gf.tables ||\n gf.tables.length === 0 ||\n gf.tables.some((t) => tableSet.has(t.toLowerCase()));\n\n if (applies) {\n matches.push({\n model: modelName,\n filter: gf,\n });\n }\n }\n }\n\n return matches;\n}\n\n/**\n * Register the `context_guardrails` tool.\n * Returns guardrail filters for given tables.\n */\nexport function registerGuardrailsTool(server: McpServer, manifest: Manifest): void {\n server.tool(\n 'context_guardrails',\n 'Return guardrail filters that apply to the specified tables',\n {\n tables: z.array(z.string()).describe('List of table names to check guardrails for'),\n },\n async ({ tables }) => {\n const results = findGuardrails(manifest, tables);\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(results, null, 2),\n },\n ],\n };\n },\n );\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,89 +1,110 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { Manifest } from '@runcontext/core';
|
|
3
|
-
import { ReadResourceResult, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { Manifest, ContextGraph, Diagnostic, TierScore, GoldenQuery, GuardrailFilter } from '@runcontext/core';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Create and configure an MCP server with all ContextKit resources and tools.
|
|
6
|
+
*
|
|
7
|
+
* Use this for testing or embedding — no transport is connected.
|
|
7
8
|
*/
|
|
8
|
-
declare function
|
|
9
|
+
declare function createServer(manifest: Manifest, graph: ContextGraph): McpServer;
|
|
10
|
+
/**
|
|
11
|
+
* Compile context, create server, and connect stdio transport.
|
|
12
|
+
*
|
|
13
|
+
* This is the main entry point for running the MCP server as a process.
|
|
14
|
+
*/
|
|
15
|
+
declare function startServer(options?: {
|
|
16
|
+
contextDir?: string;
|
|
17
|
+
rootDir?: string;
|
|
18
|
+
}): Promise<McpServer>;
|
|
9
19
|
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* Register the `context://manifest` resource.
|
|
22
|
+
* Returns the full compiled manifest as JSON.
|
|
12
23
|
*/
|
|
13
|
-
declare function
|
|
24
|
+
declare function registerManifestResource(server: McpServer, manifest: Manifest): void;
|
|
14
25
|
|
|
15
26
|
/**
|
|
16
|
-
*
|
|
27
|
+
* Build a merged view of a model: OSI model + governance + rules + lineage + tier.
|
|
17
28
|
*/
|
|
18
|
-
declare function
|
|
29
|
+
declare function buildModelView(name: string, manifest: Manifest): Record<string, unknown> | null;
|
|
19
30
|
/**
|
|
20
|
-
*
|
|
31
|
+
* Register the `context://model/{name}` resource template.
|
|
32
|
+
* Returns the OSI model merged with governance, rules, lineage, and tier data.
|
|
21
33
|
*/
|
|
22
|
-
declare function
|
|
23
|
-
resources: {
|
|
24
|
-
uri: string;
|
|
25
|
-
name: string;
|
|
26
|
-
description: string;
|
|
27
|
-
mimeType: "application/json";
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
34
|
+
declare function registerModelResource(server: McpServer, manifest: Manifest): void;
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
37
|
+
* Register the `context://glossary` resource.
|
|
38
|
+
* Returns all glossary terms as JSON.
|
|
33
39
|
*/
|
|
34
|
-
declare function
|
|
40
|
+
declare function registerGlossaryResource(server: McpServer, manifest: Manifest): void;
|
|
41
|
+
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
43
|
+
* Register the `context://tier/{name}` resource template.
|
|
44
|
+
* Returns the tier scorecard for a specific model.
|
|
37
45
|
*/
|
|
38
|
-
declare function
|
|
39
|
-
resources: {
|
|
40
|
-
uri: string;
|
|
41
|
-
name: string;
|
|
42
|
-
description: string;
|
|
43
|
-
mimeType: "application/json";
|
|
44
|
-
}[];
|
|
45
|
-
};
|
|
46
|
+
declare function registerTierResource(server: McpServer, manifest: Manifest): void;
|
|
46
47
|
|
|
48
|
+
interface SearchResult {
|
|
49
|
+
type: 'model' | 'dataset' | 'field' | 'term' | 'owner';
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
model?: string;
|
|
53
|
+
dataset?: string;
|
|
54
|
+
}
|
|
47
55
|
/**
|
|
48
|
-
*
|
|
56
|
+
* Perform keyword search across all node types in the manifest.
|
|
49
57
|
*/
|
|
50
|
-
declare function
|
|
58
|
+
declare function searchManifest(manifest: Manifest, query: string): SearchResult[];
|
|
59
|
+
|
|
60
|
+
interface ExplainResult {
|
|
61
|
+
model: Record<string, unknown>;
|
|
62
|
+
governance: Record<string, unknown> | null;
|
|
63
|
+
rules: Record<string, unknown> | null;
|
|
64
|
+
lineage: Record<string, unknown> | null;
|
|
65
|
+
tier: Record<string, unknown> | null;
|
|
66
|
+
owner: Record<string, unknown> | null;
|
|
67
|
+
relatedTerms: Record<string, unknown>[];
|
|
68
|
+
}
|
|
51
69
|
/**
|
|
52
|
-
*
|
|
70
|
+
* Deep lookup for a model with all related governance context.
|
|
53
71
|
*/
|
|
54
|
-
declare function
|
|
55
|
-
resources: {
|
|
56
|
-
uri: string;
|
|
57
|
-
name: string;
|
|
58
|
-
description: string;
|
|
59
|
-
mimeType: "application/json";
|
|
60
|
-
}[];
|
|
61
|
-
};
|
|
72
|
+
declare function explainModel(name: string, manifest: Manifest): ExplainResult | null;
|
|
62
73
|
|
|
74
|
+
interface ValidateResult {
|
|
75
|
+
totalDiagnostics: number;
|
|
76
|
+
errors: number;
|
|
77
|
+
warnings: number;
|
|
78
|
+
diagnostics: Diagnostic[];
|
|
79
|
+
}
|
|
63
80
|
/**
|
|
64
|
-
*
|
|
81
|
+
* Run the full linter against the context graph.
|
|
65
82
|
*/
|
|
66
|
-
declare function
|
|
83
|
+
declare function validateGraph(graph: ContextGraph): ValidateResult;
|
|
67
84
|
|
|
68
85
|
/**
|
|
69
|
-
*
|
|
70
|
-
* in the manifest. Matches case-insensitively on id, definition/description,
|
|
71
|
-
* and tags.
|
|
86
|
+
* Compute the tier for a model from the context graph.
|
|
72
87
|
*/
|
|
73
|
-
declare function
|
|
88
|
+
declare function computeModelTier(modelName: string, graph: ContextGraph): TierScore | null;
|
|
74
89
|
|
|
90
|
+
interface GoldenQueryMatch {
|
|
91
|
+
model: string;
|
|
92
|
+
query: GoldenQuery;
|
|
93
|
+
score: number;
|
|
94
|
+
}
|
|
75
95
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* and owner info.
|
|
96
|
+
* Find golden queries matching a natural-language question.
|
|
97
|
+
* Uses simple keyword overlap scoring.
|
|
79
98
|
*/
|
|
80
|
-
declare function
|
|
99
|
+
declare function findGoldenQueries(manifest: Manifest, question: string): GoldenQueryMatch[];
|
|
81
100
|
|
|
101
|
+
interface GuardrailMatch {
|
|
102
|
+
model: string;
|
|
103
|
+
filter: GuardrailFilter;
|
|
104
|
+
}
|
|
82
105
|
/**
|
|
83
|
-
*
|
|
106
|
+
* Find guardrail filters that apply to the given tables.
|
|
84
107
|
*/
|
|
85
|
-
declare function
|
|
86
|
-
|
|
87
|
-
declare const MCP_VERSION = "0.1.0";
|
|
108
|
+
declare function findGuardrails(manifest: Manifest, tables: string[]): GuardrailMatch[];
|
|
88
109
|
|
|
89
|
-
export {
|
|
110
|
+
export { type ExplainResult, type GoldenQueryMatch, type GuardrailMatch, type SearchResult, type ValidateResult, buildModelView, computeModelTier, createServer, explainModel, findGoldenQueries, findGuardrails, registerGlossaryResource, registerManifestResource, registerModelResource, registerTierResource, searchManifest, startServer, validateGraph };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,89 +1,110 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { Manifest } from '@runcontext/core';
|
|
3
|
-
import { ReadResourceResult, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { Manifest, ContextGraph, Diagnostic, TierScore, GoldenQuery, GuardrailFilter } from '@runcontext/core';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Create and configure an MCP server with all ContextKit resources and tools.
|
|
6
|
+
*
|
|
7
|
+
* Use this for testing or embedding — no transport is connected.
|
|
7
8
|
*/
|
|
8
|
-
declare function
|
|
9
|
+
declare function createServer(manifest: Manifest, graph: ContextGraph): McpServer;
|
|
10
|
+
/**
|
|
11
|
+
* Compile context, create server, and connect stdio transport.
|
|
12
|
+
*
|
|
13
|
+
* This is the main entry point for running the MCP server as a process.
|
|
14
|
+
*/
|
|
15
|
+
declare function startServer(options?: {
|
|
16
|
+
contextDir?: string;
|
|
17
|
+
rootDir?: string;
|
|
18
|
+
}): Promise<McpServer>;
|
|
9
19
|
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* Register the `context://manifest` resource.
|
|
22
|
+
* Returns the full compiled manifest as JSON.
|
|
12
23
|
*/
|
|
13
|
-
declare function
|
|
24
|
+
declare function registerManifestResource(server: McpServer, manifest: Manifest): void;
|
|
14
25
|
|
|
15
26
|
/**
|
|
16
|
-
*
|
|
27
|
+
* Build a merged view of a model: OSI model + governance + rules + lineage + tier.
|
|
17
28
|
*/
|
|
18
|
-
declare function
|
|
29
|
+
declare function buildModelView(name: string, manifest: Manifest): Record<string, unknown> | null;
|
|
19
30
|
/**
|
|
20
|
-
*
|
|
31
|
+
* Register the `context://model/{name}` resource template.
|
|
32
|
+
* Returns the OSI model merged with governance, rules, lineage, and tier data.
|
|
21
33
|
*/
|
|
22
|
-
declare function
|
|
23
|
-
resources: {
|
|
24
|
-
uri: string;
|
|
25
|
-
name: string;
|
|
26
|
-
description: string;
|
|
27
|
-
mimeType: "application/json";
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
34
|
+
declare function registerModelResource(server: McpServer, manifest: Manifest): void;
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
37
|
+
* Register the `context://glossary` resource.
|
|
38
|
+
* Returns all glossary terms as JSON.
|
|
33
39
|
*/
|
|
34
|
-
declare function
|
|
40
|
+
declare function registerGlossaryResource(server: McpServer, manifest: Manifest): void;
|
|
41
|
+
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
43
|
+
* Register the `context://tier/{name}` resource template.
|
|
44
|
+
* Returns the tier scorecard for a specific model.
|
|
37
45
|
*/
|
|
38
|
-
declare function
|
|
39
|
-
resources: {
|
|
40
|
-
uri: string;
|
|
41
|
-
name: string;
|
|
42
|
-
description: string;
|
|
43
|
-
mimeType: "application/json";
|
|
44
|
-
}[];
|
|
45
|
-
};
|
|
46
|
+
declare function registerTierResource(server: McpServer, manifest: Manifest): void;
|
|
46
47
|
|
|
48
|
+
interface SearchResult {
|
|
49
|
+
type: 'model' | 'dataset' | 'field' | 'term' | 'owner';
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
model?: string;
|
|
53
|
+
dataset?: string;
|
|
54
|
+
}
|
|
47
55
|
/**
|
|
48
|
-
*
|
|
56
|
+
* Perform keyword search across all node types in the manifest.
|
|
49
57
|
*/
|
|
50
|
-
declare function
|
|
58
|
+
declare function searchManifest(manifest: Manifest, query: string): SearchResult[];
|
|
59
|
+
|
|
60
|
+
interface ExplainResult {
|
|
61
|
+
model: Record<string, unknown>;
|
|
62
|
+
governance: Record<string, unknown> | null;
|
|
63
|
+
rules: Record<string, unknown> | null;
|
|
64
|
+
lineage: Record<string, unknown> | null;
|
|
65
|
+
tier: Record<string, unknown> | null;
|
|
66
|
+
owner: Record<string, unknown> | null;
|
|
67
|
+
relatedTerms: Record<string, unknown>[];
|
|
68
|
+
}
|
|
51
69
|
/**
|
|
52
|
-
*
|
|
70
|
+
* Deep lookup for a model with all related governance context.
|
|
53
71
|
*/
|
|
54
|
-
declare function
|
|
55
|
-
resources: {
|
|
56
|
-
uri: string;
|
|
57
|
-
name: string;
|
|
58
|
-
description: string;
|
|
59
|
-
mimeType: "application/json";
|
|
60
|
-
}[];
|
|
61
|
-
};
|
|
72
|
+
declare function explainModel(name: string, manifest: Manifest): ExplainResult | null;
|
|
62
73
|
|
|
74
|
+
interface ValidateResult {
|
|
75
|
+
totalDiagnostics: number;
|
|
76
|
+
errors: number;
|
|
77
|
+
warnings: number;
|
|
78
|
+
diagnostics: Diagnostic[];
|
|
79
|
+
}
|
|
63
80
|
/**
|
|
64
|
-
*
|
|
81
|
+
* Run the full linter against the context graph.
|
|
65
82
|
*/
|
|
66
|
-
declare function
|
|
83
|
+
declare function validateGraph(graph: ContextGraph): ValidateResult;
|
|
67
84
|
|
|
68
85
|
/**
|
|
69
|
-
*
|
|
70
|
-
* in the manifest. Matches case-insensitively on id, definition/description,
|
|
71
|
-
* and tags.
|
|
86
|
+
* Compute the tier for a model from the context graph.
|
|
72
87
|
*/
|
|
73
|
-
declare function
|
|
88
|
+
declare function computeModelTier(modelName: string, graph: ContextGraph): TierScore | null;
|
|
74
89
|
|
|
90
|
+
interface GoldenQueryMatch {
|
|
91
|
+
model: string;
|
|
92
|
+
query: GoldenQuery;
|
|
93
|
+
score: number;
|
|
94
|
+
}
|
|
75
95
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* and owner info.
|
|
96
|
+
* Find golden queries matching a natural-language question.
|
|
97
|
+
* Uses simple keyword overlap scoring.
|
|
79
98
|
*/
|
|
80
|
-
declare function
|
|
99
|
+
declare function findGoldenQueries(manifest: Manifest, question: string): GoldenQueryMatch[];
|
|
81
100
|
|
|
101
|
+
interface GuardrailMatch {
|
|
102
|
+
model: string;
|
|
103
|
+
filter: GuardrailFilter;
|
|
104
|
+
}
|
|
82
105
|
/**
|
|
83
|
-
*
|
|
106
|
+
* Find guardrail filters that apply to the given tables.
|
|
84
107
|
*/
|
|
85
|
-
declare function
|
|
86
|
-
|
|
87
|
-
declare const MCP_VERSION = "0.1.0";
|
|
108
|
+
declare function findGuardrails(manifest: Manifest, tables: string[]): GuardrailMatch[];
|
|
88
109
|
|
|
89
|
-
export {
|
|
110
|
+
export { type ExplainResult, type GoldenQueryMatch, type GuardrailMatch, type SearchResult, type ValidateResult, buildModelView, computeModelTier, createServer, explainModel, findGoldenQueries, findGuardrails, registerGlossaryResource, registerManifestResource, registerModelResource, registerTierResource, searchManifest, startServer, validateGraph };
|