@specprism/registry-sync 0.0.0-stage → 1.0.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/README.md +49 -2
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +251 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-registry.d.ts +28 -0
- package/dist/mcp-registry.d.ts.map +1 -0
- package/dist/mcp-registry.js +215 -0
- package/dist/mcp-registry.js.map +1 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpecPrism Contributors (@orphik)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SpecPrism (`specprism`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Turn a rough 1-to-2 sentence idea into verified, traceable software specifications (`REQ-*` <-> `TC-*`) without vibe-coding drift.**
|
|
4
|
+
|
|
5
|
+
SpecPrism is a free, open-core AI Product & QA Co-Architect usable directly in your IDE as an **Agent Skill** or **MCP `2026-07-28` Server**, via CLI (`npx specprism`), or visually in the hosted split-pane workbench at **[https://spec-prism.app](https://spec-prism.app)**.
|
|
6
|
+
|
|
7
|
+
- **Full Interactive How-To Guide (`v1.0`):** **[https://spec-prism.app/guide](https://spec-prism.app/guide)**
|
|
8
|
+
- **Verified Reference Specifications Gallery:** **[https://spec-prism.app/examples](https://spec-prism.app/examples)**
|
|
9
|
+
|
|
10
|
+
## Quickstart
|
|
11
|
+
|
|
12
|
+
### 1. Visual Web Workbench (Recommended)
|
|
13
|
+
Sign in free with **Google** or **GitHub** at **[https://spec-prism.app](https://spec-prism.app)** to co-design specifications interactively, inspect side-by-side **Annotated Dialect Diffs** across 6 model families (`Claude`, `OpenAI`, `Gemini`, `DeepSeek`, `Qwen`, `Ollama`), get auto-matched Official MCP Registry tools, and export Gherkin/Playwright `.zip` test bundles.
|
|
14
|
+
|
|
15
|
+
### 2. Install as an Agent Skill or Run via npm CLI
|
|
16
|
+
```bash
|
|
17
|
+
# Install zero-dependency Agent Skill (Antigravity, Claude Code, Cursor, Codex)
|
|
18
|
+
npx skills add orphik/specprism
|
|
19
|
+
|
|
20
|
+
# Or run the SpecPrism v1.0 CLI & stdio MCP server directly from npm
|
|
21
|
+
npx specprism@latest --help
|
|
22
|
+
npx specprism@latest validate .specprism/spec.json
|
|
23
|
+
npx specprism@latest mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. Connect via Stateless MCP (`2026-07-28`) or Local CLI
|
|
27
|
+
Mint an optional cloud-sync token (`sp_pat_*`) at **[https://spec-prism.app/settings](https://spec-prism.app/settings)** or connect directly via Streamable HTTP / local `stdio` (`npx specprism mcp`):
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"specprism": {
|
|
32
|
+
"url": "https://spec-prism.app/mcp",
|
|
33
|
+
"serverUrl": "https://spec-prism.app/mcp",
|
|
34
|
+
"headers": {
|
|
35
|
+
"Authorization": "Bearer sp_pat_YOUR_OPTIONAL_SYNC_TOKEN"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Core 5-Stage Pipeline
|
|
43
|
+
1. **Socratic Scope & Boundary Triage** — Surfaces 3–4 clickable/editable ambiguity forks (`ASM-*`).
|
|
44
|
+
2. **Vertical-Slice Feature & Story Decomposition** — Enforces end-to-end UI + Domain + Persistence slices (`US-*`) + Official MCP Registry recommendations.
|
|
45
|
+
3. **Guided Acceptance Criteria Co-Design** — Generates deterministic Given/When/Then + EARS (`REQ-*`) with inline QA coaching.
|
|
46
|
+
4. **Traceable Test Blueprint & Dialect Diff Coach** — Maps every `REQ-*` to `TC-*` across Unit, API Contract, and Playwright/Gherkin tiers and compiles vendor-tuned handoff prompts across 6 model dialects.
|
|
47
|
+
5. **Iterative Delta Mode** — Computes `ADDED`, `MODIFIED`, and `REMOVED` deltas while badging existing tests as Regression Shields.
|
|
48
|
+
|
|
49
|
+
## Keep SpecPrism Free & Evergreen
|
|
50
|
+
SpecPrism is free to use and open-core (MIT). If SpecPrism saves your team hours of rework, consider supporting ongoing AI/MCP radar maintenance via **[GitHub Sponsors](https://github.com/sponsors/orphik)** or at **[spec-prism.app](https://spec-prism.app)**.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type AnySpecPrismDrizzleDb } from "@specprism/db";
|
|
2
|
+
export declare const UPSTREAM_CATALOG_ENDPOINTS: {
|
|
3
|
+
readonly openRouterModels: "https://openrouter.ai/api/v1/models";
|
|
4
|
+
readonly liteLlmPricing: "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
|
|
5
|
+
readonly officialMcpRegistry: "https://registry.modelcontextprotocol.io/v0/servers";
|
|
6
|
+
readonly defaultOllamaTags: "http://127.0.0.1:11434/api/tags";
|
|
7
|
+
};
|
|
8
|
+
export * from "./mcp-registry.js";
|
|
9
|
+
export declare const CURATED_PROVIDER_PRIORITY: Record<string, {
|
|
10
|
+
label: string;
|
|
11
|
+
rank: number;
|
|
12
|
+
}>;
|
|
13
|
+
export interface EtagCacheMetadata {
|
|
14
|
+
etag?: string;
|
|
15
|
+
fetchedAtIso: string;
|
|
16
|
+
ttlSeconds: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function isCacheFresh(meta: EtagCacheMetadata | undefined, nowMs?: number): boolean;
|
|
19
|
+
export interface OpenRouterRawModel {
|
|
20
|
+
id: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
context_length?: number;
|
|
23
|
+
architecture?: {
|
|
24
|
+
modality?: string;
|
|
25
|
+
output_modalities?: string[];
|
|
26
|
+
};
|
|
27
|
+
top_provider?: {
|
|
28
|
+
max_completion_tokens?: number | null;
|
|
29
|
+
};
|
|
30
|
+
supported_parameters?: string[];
|
|
31
|
+
pricing?: {
|
|
32
|
+
prompt?: string;
|
|
33
|
+
completion?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface NormalizedAiModelRow {
|
|
37
|
+
id: string;
|
|
38
|
+
provider: string;
|
|
39
|
+
displayName: string;
|
|
40
|
+
contextWindow: number;
|
|
41
|
+
maxOutputTokens: number | null;
|
|
42
|
+
supportsStructuredOutput: boolean;
|
|
43
|
+
supportsTools: boolean;
|
|
44
|
+
supportsReasoning: boolean;
|
|
45
|
+
inputCostPerMillionUsd: string | null;
|
|
46
|
+
outputCostPerMillionUsd: string | null;
|
|
47
|
+
sourceCatalog: string;
|
|
48
|
+
sourceEtag: string | null;
|
|
49
|
+
}
|
|
50
|
+
export declare function cleanModelDisplayName(rawName: string, modelId: string): string;
|
|
51
|
+
export declare function formatContextWindowLabel(tokens: number): string;
|
|
52
|
+
export declare function isCuratedProvider(provider: string): boolean;
|
|
53
|
+
export declare function getProviderDisplayLabel(provider: string): string;
|
|
54
|
+
export declare function normalizeOpenRouterModels(rawModels: OpenRouterRawModel[], etag?: string | null): NormalizedAiModelRow[];
|
|
55
|
+
export declare function isFreeTierEligibleModel(model: {
|
|
56
|
+
id?: string;
|
|
57
|
+
contextWindow: number;
|
|
58
|
+
supportsStructuredOutput: boolean;
|
|
59
|
+
supportsTools: boolean;
|
|
60
|
+
inputCostPerMillionUsd: string | number | null;
|
|
61
|
+
outputCostPerMillionUsd: string | number | null;
|
|
62
|
+
sourceCatalog?: string;
|
|
63
|
+
}): boolean;
|
|
64
|
+
export declare function pickRecommendedModels<T extends {
|
|
65
|
+
id: string;
|
|
66
|
+
provider: string;
|
|
67
|
+
supportsStructuredOutput: boolean;
|
|
68
|
+
supportsReasoning: boolean;
|
|
69
|
+
freeTierEligible: boolean;
|
|
70
|
+
}>(models: T[], unlockedByokProviders?: ReadonlySet<string>): {
|
|
71
|
+
fastFreeModelId: string | undefined;
|
|
72
|
+
deepReasoningModelId: string | undefined;
|
|
73
|
+
};
|
|
74
|
+
export declare function ensureFreshModelCatalog(db: AnySpecPrismDrizzleDb, options?: {
|
|
75
|
+
ttlSeconds?: number;
|
|
76
|
+
ollamaBaseUrl?: string;
|
|
77
|
+
probeOllama?: boolean;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAErE,eAAO,MAAM,0BAA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AS,CAAC;CAC1C,CA6BA;AAED,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,qBAAqB,EACzB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACnF,OAAO,CAAC,IAAI,CAAC,CA0Gf"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { desc, like, or, sql } from "drizzle-orm";
|
|
2
|
+
import { aiModels } from "@specprism/db";
|
|
3
|
+
export const UPSTREAM_CATALOG_ENDPOINTS = {
|
|
4
|
+
openRouterModels: "https://openrouter.ai/api/v1/models",
|
|
5
|
+
liteLlmPricing: "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json",
|
|
6
|
+
officialMcpRegistry: "https://registry.modelcontextprotocol.io/v0/servers",
|
|
7
|
+
defaultOllamaTags: "http://127.0.0.1:11434/api/tags",
|
|
8
|
+
};
|
|
9
|
+
export * from "./mcp-registry.js";
|
|
10
|
+
export const CURATED_PROVIDER_PRIORITY = {
|
|
11
|
+
anthropic: { label: "Anthropic", rank: 1 },
|
|
12
|
+
google: { label: "Google", rank: 2 },
|
|
13
|
+
openai: { label: "OpenAI", rank: 3 },
|
|
14
|
+
deepseek: { label: "DeepSeek", rank: 4 },
|
|
15
|
+
"x-ai": { label: "xAI", rank: 5 },
|
|
16
|
+
qwen: { label: "Qwen", rank: 6 },
|
|
17
|
+
meta: { label: "Meta", rank: 7 },
|
|
18
|
+
"meta-llama": { label: "Meta", rank: 7 },
|
|
19
|
+
mistralai: { label: "Mistral", rank: 8 },
|
|
20
|
+
ollama: { label: "Local Ollama", rank: 9 },
|
|
21
|
+
};
|
|
22
|
+
const NON_CHAT_MODEL_PATTERN = /\b(image|imagen|flux|stable-diffusion|sdxl|whisper|tts|audio|embed|embedding|moderation|rerank|nano-banana|vision-only)\b/i;
|
|
23
|
+
export function isCacheFresh(meta, nowMs = Date.now()) {
|
|
24
|
+
if (!meta)
|
|
25
|
+
return false;
|
|
26
|
+
const ageMs = nowMs - new Date(meta.fetchedAtIso).getTime();
|
|
27
|
+
return ageMs >= 0 && ageMs < meta.ttlSeconds * 1_000;
|
|
28
|
+
}
|
|
29
|
+
export function cleanModelDisplayName(rawName, modelId) {
|
|
30
|
+
const base = (rawName || modelId)
|
|
31
|
+
.replace(/\s*\((?:free|batch|extended|preview)\)\s*/gi, " ")
|
|
32
|
+
.replace(/\s+/g, " ")
|
|
33
|
+
.trim();
|
|
34
|
+
const colonIdx = base.indexOf(":");
|
|
35
|
+
if (colonIdx > 0 && colonIdx < 24) {
|
|
36
|
+
return base.slice(colonIdx + 1).trim();
|
|
37
|
+
}
|
|
38
|
+
return base;
|
|
39
|
+
}
|
|
40
|
+
export function formatContextWindowLabel(tokens) {
|
|
41
|
+
if (tokens >= 950_000)
|
|
42
|
+
return "1M context";
|
|
43
|
+
if (tokens >= 450_000)
|
|
44
|
+
return "500K context";
|
|
45
|
+
if (tokens >= 190_000)
|
|
46
|
+
return "200K context";
|
|
47
|
+
if (tokens >= 120_000)
|
|
48
|
+
return "128K context";
|
|
49
|
+
if (tokens >= 60_000)
|
|
50
|
+
return "64K context";
|
|
51
|
+
return `${Math.round(tokens / 1024)}K context`;
|
|
52
|
+
}
|
|
53
|
+
export function isCuratedProvider(provider) {
|
|
54
|
+
return Boolean(CURATED_PROVIDER_PRIORITY[provider.toLowerCase()]);
|
|
55
|
+
}
|
|
56
|
+
export function getProviderDisplayLabel(provider) {
|
|
57
|
+
return (CURATED_PROVIDER_PRIORITY[provider.toLowerCase()]?.label ??
|
|
58
|
+
provider.charAt(0).toUpperCase() + provider.slice(1));
|
|
59
|
+
}
|
|
60
|
+
export function normalizeOpenRouterModels(rawModels, etag) {
|
|
61
|
+
const rows = [];
|
|
62
|
+
for (const m of rawModels) {
|
|
63
|
+
if (!m.id || !m.context_length || m.context_length < 16_384)
|
|
64
|
+
continue;
|
|
65
|
+
// Exclude offline :batch endpoints and internal ~router aliases
|
|
66
|
+
if (m.id.startsWith("~"))
|
|
67
|
+
continue;
|
|
68
|
+
if (m.id.includes(":batch") || /\(batch\)/i.test(m.name ?? ""))
|
|
69
|
+
continue;
|
|
70
|
+
// Exclude image/audio/embedding-only models
|
|
71
|
+
const outModalities = m.architecture?.output_modalities;
|
|
72
|
+
if (Array.isArray(outModalities) && outModalities.length > 0 && !outModalities.includes("text")) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (m.architecture?.modality &&
|
|
76
|
+
!m.architecture.modality.toLowerCase().includes("->text") &&
|
|
77
|
+
m.architecture.modality.includes("->")) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (NON_CHAT_MODEL_PATTERN.test(m.id) || NON_CHAT_MODEL_PATTERN.test(m.name ?? "")) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const slashIdx = m.id.indexOf("/");
|
|
84
|
+
const provider = slashIdx > 0 ? m.id.slice(0, slashIdx).toLowerCase() : "openrouter";
|
|
85
|
+
const params = new Set(m.supported_parameters ?? []);
|
|
86
|
+
const promptPerToken = m.pricing?.prompt ? Number(m.pricing.prompt) : NaN;
|
|
87
|
+
const completionPerToken = m.pricing?.completion ? Number(m.pricing.completion) : NaN;
|
|
88
|
+
const inputPerMillion = Number.isFinite(promptPerToken) && promptPerToken >= 0
|
|
89
|
+
? (promptPerToken * 1_000_000).toFixed(4)
|
|
90
|
+
: null;
|
|
91
|
+
const outputPerMillion = Number.isFinite(completionPerToken) && completionPerToken >= 0
|
|
92
|
+
? (completionPerToken * 1_000_000).toFixed(4)
|
|
93
|
+
: null;
|
|
94
|
+
rows.push({
|
|
95
|
+
id: m.id,
|
|
96
|
+
provider,
|
|
97
|
+
displayName: cleanModelDisplayName(m.name ?? m.id, m.id),
|
|
98
|
+
contextWindow: m.context_length,
|
|
99
|
+
maxOutputTokens: m.top_provider?.max_completion_tokens ?? null,
|
|
100
|
+
supportsStructuredOutput: params.has("structured_outputs") || params.has("response_format"),
|
|
101
|
+
supportsTools: params.has("tools") || params.has("tool_choice"),
|
|
102
|
+
supportsReasoning: params.has("reasoning") ||
|
|
103
|
+
params.has("include_reasoning") ||
|
|
104
|
+
/\b(r1|o1|o3|o4|thinking|reasoner|opus|sonnet|pro)\b/i.test(m.id),
|
|
105
|
+
inputCostPerMillionUsd: inputPerMillion,
|
|
106
|
+
outputCostPerMillionUsd: outputPerMillion,
|
|
107
|
+
sourceCatalog: "openrouter",
|
|
108
|
+
sourceEtag: etag ?? null,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// Sort curated Tier-1 providers & structured-output models first before slicing
|
|
112
|
+
rows.sort((a, b) => {
|
|
113
|
+
const rankA = CURATED_PROVIDER_PRIORITY[a.provider]?.rank ?? 99;
|
|
114
|
+
const rankB = CURATED_PROVIDER_PRIORITY[b.provider]?.rank ?? 99;
|
|
115
|
+
if (rankA !== rankB)
|
|
116
|
+
return rankA - rankB;
|
|
117
|
+
if (a.supportsStructuredOutput !== b.supportsStructuredOutput) {
|
|
118
|
+
return a.supportsStructuredOutput ? -1 : 1;
|
|
119
|
+
}
|
|
120
|
+
return a.displayName.localeCompare(b.displayName);
|
|
121
|
+
});
|
|
122
|
+
return rows;
|
|
123
|
+
}
|
|
124
|
+
export function isFreeTierEligibleModel(model) {
|
|
125
|
+
if (model.id && (model.id.includes(":batch") || model.id.startsWith("~")))
|
|
126
|
+
return false;
|
|
127
|
+
if (model.sourceCatalog === "ollama")
|
|
128
|
+
return true;
|
|
129
|
+
if (model.contextWindow < 32_768)
|
|
130
|
+
return false;
|
|
131
|
+
if (!model.supportsStructuredOutput && !model.supportsTools)
|
|
132
|
+
return false;
|
|
133
|
+
const inCost = model.inputCostPerMillionUsd !== null ? Number(model.inputCostPerMillionUsd) : NaN;
|
|
134
|
+
const outCost = model.outputCostPerMillionUsd !== null ? Number(model.outputCostPerMillionUsd) : NaN;
|
|
135
|
+
if (!Number.isFinite(inCost) || !Number.isFinite(outCost))
|
|
136
|
+
return false;
|
|
137
|
+
return inCost <= 0.8 && outCost <= 3.5;
|
|
138
|
+
}
|
|
139
|
+
export function pickRecommendedModels(models, unlockedByokProviders = new Set()) {
|
|
140
|
+
const hasUniversalKey = unlockedByokProviders.has("openrouter");
|
|
141
|
+
// Best fast Free-Tier model from trusted Tier-1 labs first
|
|
142
|
+
const freePool = models.filter((m) => m.freeTierEligible && !m.id.endsWith(":free"));
|
|
143
|
+
const tier1Free = freePool.filter((m) => (m.provider === "anthropic" || m.provider === "google" || m.provider === "openai") &&
|
|
144
|
+
m.supportsStructuredOutput);
|
|
145
|
+
const fastFree = tier1Free[0] ?? freePool.find((m) => isCuratedProvider(m.provider)) ?? freePool[0] ?? models[0];
|
|
146
|
+
// Best Deep Reasoning model (preferring unlocked BYOK provider if user added a key)
|
|
147
|
+
const reasoningPool = models.filter((m) => m.supportsReasoning &&
|
|
148
|
+
isCuratedProvider(m.provider) &&
|
|
149
|
+
(hasUniversalKey ||
|
|
150
|
+
unlockedByokProviders.size === 0 ||
|
|
151
|
+
unlockedByokProviders.has(m.provider) ||
|
|
152
|
+
m.freeTierEligible));
|
|
153
|
+
const nonFreeFrontierReasoning = reasoningPool.find((m) => !m.freeTierEligible);
|
|
154
|
+
const deepReasoning = nonFreeFrontierReasoning ?? reasoningPool[0] ?? fastFree;
|
|
155
|
+
return {
|
|
156
|
+
fastFreeModelId: fastFree?.id,
|
|
157
|
+
deepReasoningModelId: deepReasoning?.id,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export async function ensureFreshModelCatalog(db, options = {}) {
|
|
161
|
+
const ttlSeconds = options.ttlSeconds ?? 14_400;
|
|
162
|
+
// Always purge any legacy :batch, ~alias, or image-only rows so invalid endpoints never appear
|
|
163
|
+
await db
|
|
164
|
+
.delete(aiModels)
|
|
165
|
+
.where(or(like(aiModels.id, "%:batch%"), like(aiModels.id, "~%"), like(aiModels.id, "%image%"), like(aiModels.id, "%nano-banana%")));
|
|
166
|
+
const latest = await db
|
|
167
|
+
.select({ syncedAt: aiModels.syncedAt, sourceEtag: aiModels.sourceEtag })
|
|
168
|
+
.from(aiModels)
|
|
169
|
+
.orderBy(desc(aiModels.syncedAt))
|
|
170
|
+
.limit(1);
|
|
171
|
+
const recentRow = latest[0];
|
|
172
|
+
if (recentRow &&
|
|
173
|
+
isCacheFresh({
|
|
174
|
+
etag: recentRow.sourceEtag ?? undefined,
|
|
175
|
+
fetchedAtIso: recentRow.syncedAt.toISOString(),
|
|
176
|
+
ttlSeconds,
|
|
177
|
+
})) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const res = await fetch(UPSTREAM_CATALOG_ENDPOINTS.openRouterModels, {
|
|
182
|
+
headers: { Accept: "application/json" },
|
|
183
|
+
signal: AbortSignal.timeout(8_000),
|
|
184
|
+
});
|
|
185
|
+
if (res.status === 200) {
|
|
186
|
+
const etag = res.headers.get("etag");
|
|
187
|
+
const json = (await res.json());
|
|
188
|
+
const normalized = normalizeOpenRouterModels(json.data ?? [], etag).slice(0, 180);
|
|
189
|
+
for (const row of normalized) {
|
|
190
|
+
await db
|
|
191
|
+
.insert(aiModels)
|
|
192
|
+
.values({
|
|
193
|
+
...row,
|
|
194
|
+
syncedAt: new Date(),
|
|
195
|
+
})
|
|
196
|
+
.onConflictDoUpdate({
|
|
197
|
+
target: aiModels.id,
|
|
198
|
+
set: {
|
|
199
|
+
displayName: row.displayName,
|
|
200
|
+
contextWindow: row.contextWindow,
|
|
201
|
+
maxOutputTokens: row.maxOutputTokens,
|
|
202
|
+
supportsStructuredOutput: row.supportsStructuredOutput,
|
|
203
|
+
supportsTools: row.supportsTools,
|
|
204
|
+
supportsReasoning: row.supportsReasoning,
|
|
205
|
+
inputCostPerMillionUsd: row.inputCostPerMillionUsd,
|
|
206
|
+
outputCostPerMillionUsd: row.outputCostPerMillionUsd,
|
|
207
|
+
sourceEtag: row.sourceEtag,
|
|
208
|
+
syncedAt: sql `now()`,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// Gracefully tolerate offline / air-gapped environments
|
|
216
|
+
}
|
|
217
|
+
if (options.probeOllama) {
|
|
218
|
+
try {
|
|
219
|
+
const base = (options.ollamaBaseUrl ?? "http://127.0.0.1:11434").replace(/\/$/, "");
|
|
220
|
+
const res = await fetch(`${base}/api/tags`, { signal: AbortSignal.timeout(1_200) });
|
|
221
|
+
if (res.ok) {
|
|
222
|
+
const payload = (await res.json());
|
|
223
|
+
for (const m of payload.models ?? []) {
|
|
224
|
+
const id = `ollama/${m.name}`;
|
|
225
|
+
await db
|
|
226
|
+
.insert(aiModels)
|
|
227
|
+
.values({
|
|
228
|
+
id,
|
|
229
|
+
provider: "ollama",
|
|
230
|
+
displayName: m.name,
|
|
231
|
+
contextWindow: 32768,
|
|
232
|
+
supportsStructuredOutput: true,
|
|
233
|
+
supportsTools: true,
|
|
234
|
+
supportsReasoning: /r1|qwq|think/i.test(m.name),
|
|
235
|
+
inputCostPerMillionUsd: "0.0000",
|
|
236
|
+
outputCostPerMillionUsd: "0.0000",
|
|
237
|
+
sourceCatalog: "ollama",
|
|
238
|
+
})
|
|
239
|
+
.onConflictDoUpdate({
|
|
240
|
+
target: aiModels.id,
|
|
241
|
+
set: { syncedAt: sql `now()` },
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
// No local Ollama running — ignore silently
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAA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CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACpF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACpF,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;gBACX,MAAM,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAEhC,CAAC;gBACF,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;oBACrC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;oBAC9B,MAAM,EAAE;yBACL,MAAM,CAAC,QAAQ,CAAC;yBAChB,MAAM,CAAC;wBACN,EAAE;wBACF,QAAQ,EAAE,QAAQ;wBAClB,WAAW,EAAE,CAAC,CAAC,IAAI;wBACnB,aAAa,EAAE,KAAK;wBACpB,wBAAwB,EAAE,IAAI;wBAC9B,aAAa,EAAE,IAAI;wBACnB,iBAAiB,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;wBAC/C,sBAAsB,EAAE,QAAQ;wBAChC,uBAAuB,EAAE,QAAQ;wBACjC,aAAa,EAAE,QAAQ;qBACxB,CAAC;yBACD,kBAAkB,CAAC;wBAClB,MAAM,EAAE,QAAQ,CAAC,EAAE;wBACnB,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAA,OAAO,EAAE;qBAC9B,CAAC,CAAC;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,4CAA4C;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { McpRecommendation, VerticalStory } from "@specprism/core";
|
|
2
|
+
import { type AnySpecPrismDrizzleDb } from "@specprism/db";
|
|
3
|
+
export interface CuratedMcpSeed {
|
|
4
|
+
id: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
description: string;
|
|
7
|
+
transport: "stdio" | "streamable_http";
|
|
8
|
+
endpointOrCommand: string;
|
|
9
|
+
repositoryUrl: string;
|
|
10
|
+
tags: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const CURATED_MCP_SERVERS: CuratedMcpSeed[];
|
|
13
|
+
export declare function syncMcpRegistryToDb(db: AnySpecPrismDrizzleDb): Promise<number>;
|
|
14
|
+
export declare function recommendMcpsForStories(params: {
|
|
15
|
+
scopedVisionSummary: string;
|
|
16
|
+
stories: VerticalStory[];
|
|
17
|
+
explicitOutOfScopeV1?: string[];
|
|
18
|
+
availableServers?: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
displayName: string;
|
|
21
|
+
description: string;
|
|
22
|
+
transport: string;
|
|
23
|
+
endpointOrCommand: string;
|
|
24
|
+
tags: string[];
|
|
25
|
+
}>;
|
|
26
|
+
maxRecommendations?: number;
|
|
27
|
+
}): McpRecommendation[];
|
|
28
|
+
//# sourceMappingURL=mcp-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-registry.d.ts","sourceRoot":"","sources":["../src/mcp-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,KAAK,qBAAqB,EAAc,MAAM,eAAe,CAAC;AAGvE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACvC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,eAAO,MAAM,mBAAmB,EAAE,cAAc,EAuD/C,CAAC;AAyBF,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CA8FpF;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC9C,mBAAmB,EAAE,MAAM,CAAC;IAC5B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,gBAAgB,CAAC,EAAE,KAAK,CAAC;QACvB,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,CAAC,CAAC;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,GAAG,iBAAiB,EAAE,CAuDtB"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { mcpServers } from "@specprism/db";
|
|
3
|
+
import { UPSTREAM_CATALOG_ENDPOINTS } from "./index.js";
|
|
4
|
+
export const CURATED_MCP_SERVERS = [
|
|
5
|
+
{
|
|
6
|
+
id: "io.modelcontextprotocol/playwright",
|
|
7
|
+
displayName: "Playwright Browser MCP",
|
|
8
|
+
description: "Deterministic browser automation, accessibility snapshots, and E2E UI verification.",
|
|
9
|
+
transport: "stdio",
|
|
10
|
+
endpointOrCommand: "npx @playwright/mcp@latest",
|
|
11
|
+
repositoryUrl: "https://github.com/microsoft/playwright-mcp",
|
|
12
|
+
tags: ["ui", "browser", "e2e", "playwright", "frontend", "form", "dashboard", "nextjs", "react"],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "io.modelcontextprotocol/postgres",
|
|
16
|
+
displayName: "PostgreSQL Schema & Query MCP",
|
|
17
|
+
description: "Inspect PostgreSQL tables, indexes, constraints, and execute read-only verification queries.",
|
|
18
|
+
transport: "stdio",
|
|
19
|
+
endpointOrCommand: "npx -y @modelcontextprotocol/server-postgres",
|
|
20
|
+
repositoryUrl: "https://github.com/modelcontextprotocol/servers",
|
|
21
|
+
tags: ["postgres", "postgresql", "database", "sql", "drizzle", "prisma", "table", "migration"],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "io.modelcontextprotocol/github",
|
|
25
|
+
displayName: "GitHub Repository & PR MCP",
|
|
26
|
+
description: "Manage issues, pull requests, branches, workflows, and code reviews via GitHub API.",
|
|
27
|
+
transport: "streamable_http",
|
|
28
|
+
endpointOrCommand: "https://api.githubcopilot.com/mcp/",
|
|
29
|
+
repositoryUrl: "https://github.com/github/github-mcp-server",
|
|
30
|
+
tags: ["github", "git", "pull-request", "ci", "actions", "repo", "webhook"],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "com.stripe/mcp",
|
|
34
|
+
displayName: "Stripe Billing & Webhooks MCP",
|
|
35
|
+
description: "Create payment intents, subscriptions, invoices, checkout sessions, and inspect webhook events.",
|
|
36
|
+
transport: "stdio",
|
|
37
|
+
endpointOrCommand: "npx -y @stripe/mcp --tools=all",
|
|
38
|
+
repositoryUrl: "https://github.com/stripe/agent-toolkit",
|
|
39
|
+
tags: ["stripe", "payment", "invoice", "billing", "subscription", "checkout", "saas", "fintech"],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "com.cloudflare/mcp",
|
|
43
|
+
displayName: "Cloudflare Workers, DNS & Edge MCP",
|
|
44
|
+
description: "Inspect and manage Cloudflare DNS, Workers, KV, D1, R2, and Zero Trust configurations.",
|
|
45
|
+
transport: "streamable_http",
|
|
46
|
+
endpointOrCommand: "https://mcp.cloudflare.com/mcp",
|
|
47
|
+
repositoryUrl: "https://github.com/cloudflare/mcp-server-cloudflare",
|
|
48
|
+
tags: ["cloudflare", "dns", "worker", "edge", "cdn", "r2", "kv", "rate-limit"],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "io.modelcontextprotocol/fetch",
|
|
52
|
+
displayName: "HTTP & Webhook Contract Fetch MCP",
|
|
53
|
+
description: "Fetch, inspect, and validate external HTTP REST endpoints, payloads, and OpenAPI docs.",
|
|
54
|
+
transport: "stdio",
|
|
55
|
+
endpointOrCommand: "npx -y @modelcontextprotocol/server-fetch",
|
|
56
|
+
repositoryUrl: "https://github.com/modelcontextprotocol/servers",
|
|
57
|
+
tags: ["webhook", "http", "api", "rest", "ingest", "proxy", "endpoint", "json"],
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
function buildKeywordEmbedding(text) {
|
|
61
|
+
// Deterministic 384-dim feature-hashed unit vector so pgvector cosine similarity works zero-API-key offline & online!
|
|
62
|
+
const vec = new Array(384).fill(0);
|
|
63
|
+
const tokens = text
|
|
64
|
+
.toLowerCase()
|
|
65
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
66
|
+
.split(" ")
|
|
67
|
+
.filter((t) => t.length >= 2);
|
|
68
|
+
for (const tok of tokens) {
|
|
69
|
+
let hash = 2166136261;
|
|
70
|
+
for (let i = 0; i < tok.length; i += 1) {
|
|
71
|
+
hash ^= tok.charCodeAt(i);
|
|
72
|
+
hash = Math.imul(hash, 16777619);
|
|
73
|
+
}
|
|
74
|
+
const idx = Math.abs(hash) % 384;
|
|
75
|
+
vec[idx] = (vec[idx] ?? 0) + 1;
|
|
76
|
+
}
|
|
77
|
+
const norm = Math.sqrt(vec.reduce((sum, v) => sum + v * v, 0)) || 1;
|
|
78
|
+
return vec.map((v) => Number((v / norm).toFixed(6)));
|
|
79
|
+
}
|
|
80
|
+
export async function syncMcpRegistryToDb(db) {
|
|
81
|
+
let upserted = 0;
|
|
82
|
+
// 1. Always ensure curated high-trust MCP servers exist with deterministic embeddings
|
|
83
|
+
for (const seed of CURATED_MCP_SERVERS) {
|
|
84
|
+
const emb = buildKeywordEmbedding(`${seed.displayName} ${seed.description} ${seed.tags.join(" ")}`);
|
|
85
|
+
await db
|
|
86
|
+
.insert(mcpServers)
|
|
87
|
+
.values({
|
|
88
|
+
id: seed.id,
|
|
89
|
+
displayName: seed.displayName,
|
|
90
|
+
description: seed.description,
|
|
91
|
+
transport: seed.transport,
|
|
92
|
+
endpointOrCommand: seed.endpointOrCommand,
|
|
93
|
+
repositoryUrl: seed.repositoryUrl,
|
|
94
|
+
tags: seed.tags,
|
|
95
|
+
embedding: emb,
|
|
96
|
+
syncedAt: new Date(),
|
|
97
|
+
})
|
|
98
|
+
.onConflictDoUpdate({
|
|
99
|
+
target: mcpServers.id,
|
|
100
|
+
set: {
|
|
101
|
+
displayName: seed.displayName,
|
|
102
|
+
description: seed.description,
|
|
103
|
+
tags: seed.tags,
|
|
104
|
+
embedding: emb,
|
|
105
|
+
syncedAt: sql `now()`,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
upserted += 1;
|
|
109
|
+
}
|
|
110
|
+
// 2. Pull live entries from Official MCP Registry (`registry.modelcontextprotocol.io`)
|
|
111
|
+
try {
|
|
112
|
+
const res = await fetch(`${UPSTREAM_CATALOG_ENDPOINTS.officialMcpRegistry}?limit=40`, {
|
|
113
|
+
headers: { Accept: "application/json" },
|
|
114
|
+
signal: AbortSignal.timeout(6_000),
|
|
115
|
+
});
|
|
116
|
+
if (res.ok) {
|
|
117
|
+
const data = (await res.json());
|
|
118
|
+
for (const srv of data.servers ?? []) {
|
|
119
|
+
if (!srv.name || !srv.description)
|
|
120
|
+
continue;
|
|
121
|
+
const remote = srv.remotes?.[0];
|
|
122
|
+
const pkg = srv.packages?.[0];
|
|
123
|
+
const transport = remote?.url ? "streamable_http" : "stdio";
|
|
124
|
+
const endpoint = remote?.url ??
|
|
125
|
+
(pkg?.name ? `npx -y ${pkg.name}` : `mcp://${srv.name}`);
|
|
126
|
+
const words = `${srv.name} ${srv.description}`
|
|
127
|
+
.toLowerCase()
|
|
128
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
129
|
+
.split(" ")
|
|
130
|
+
.filter((w) => w.length >= 3)
|
|
131
|
+
.slice(0, 12);
|
|
132
|
+
const emb = buildKeywordEmbedding(`${srv.name} ${srv.description}`);
|
|
133
|
+
await db
|
|
134
|
+
.insert(mcpServers)
|
|
135
|
+
.values({
|
|
136
|
+
id: srv.name,
|
|
137
|
+
displayName: srv.name.split("/").pop() ?? srv.name,
|
|
138
|
+
description: srv.description.slice(0, 280),
|
|
139
|
+
transport,
|
|
140
|
+
endpointOrCommand: endpoint,
|
|
141
|
+
repositoryUrl: srv.repository?.url ?? null,
|
|
142
|
+
tags: words,
|
|
143
|
+
embedding: emb,
|
|
144
|
+
syncedAt: new Date(),
|
|
145
|
+
})
|
|
146
|
+
.onConflictDoUpdate({
|
|
147
|
+
target: mcpServers.id,
|
|
148
|
+
set: {
|
|
149
|
+
description: srv.description.slice(0, 280),
|
|
150
|
+
endpointOrCommand: endpoint,
|
|
151
|
+
embedding: emb,
|
|
152
|
+
syncedAt: sql `now()`,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
upserted += 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Gracefully fall back to curated MCP catalog when offline
|
|
161
|
+
}
|
|
162
|
+
return upserted;
|
|
163
|
+
}
|
|
164
|
+
export function recommendMcpsForStories(params) {
|
|
165
|
+
const catalog = params.availableServers?.length ? params.availableServers : CURATED_MCP_SERVERS;
|
|
166
|
+
const max = params.maxRecommendations ?? 3;
|
|
167
|
+
const outOfScopeCorpus = (params.explicitOutOfScopeV1 ?? []).join(" ").toLowerCase();
|
|
168
|
+
const scored = catalog.map((srv) => {
|
|
169
|
+
const matchedStoryIds = [];
|
|
170
|
+
let score = 0;
|
|
171
|
+
for (const story of params.stories) {
|
|
172
|
+
const touchpointsCorpus = [
|
|
173
|
+
story.touchpoints.entrySurface,
|
|
174
|
+
story.touchpoints.domainLogic,
|
|
175
|
+
story.touchpoints.persistenceOrExternal,
|
|
176
|
+
]
|
|
177
|
+
.join(" ")
|
|
178
|
+
.toLowerCase();
|
|
179
|
+
const storyTextCorpus = `${story.title} ${story.iWant}`.toLowerCase();
|
|
180
|
+
let storyHits = 0;
|
|
181
|
+
for (const rawTag of srv.tags ?? []) {
|
|
182
|
+
const tag = rawTag.toLowerCase();
|
|
183
|
+
// Require whole-word or prefix boundary match and prioritize concrete touchpoints over incidental nouns
|
|
184
|
+
if (touchpointsCorpus.includes(tag)) {
|
|
185
|
+
storyHits += 2;
|
|
186
|
+
}
|
|
187
|
+
else if (storyTextCorpus.includes(tag) && !outOfScopeCorpus.includes(tag)) {
|
|
188
|
+
storyHits += 1;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (storyHits >= 2) {
|
|
192
|
+
matchedStoryIds.push(story.id);
|
|
193
|
+
score += storyHits;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Boost curated official MCPs slightly on tie-breaks
|
|
197
|
+
if (srv.id.startsWith("io.modelcontextprotocol/") || srv.id.startsWith("com.")) {
|
|
198
|
+
score += 0.5;
|
|
199
|
+
}
|
|
200
|
+
return { srv, score, matchedStoryIds };
|
|
201
|
+
});
|
|
202
|
+
return scored
|
|
203
|
+
.filter((item) => item.score >= 2 && item.matchedStoryIds.length > 0)
|
|
204
|
+
.sort((a, b) => b.score - a.score)
|
|
205
|
+
.slice(0, max)
|
|
206
|
+
.map(({ srv, matchedStoryIds }) => ({
|
|
207
|
+
registryId: srv.id,
|
|
208
|
+
displayName: srv.displayName,
|
|
209
|
+
transport: srv.transport === "streamable_http" ? "streamable_http" : "stdio",
|
|
210
|
+
serverUrlOrCommand: srv.endpointOrCommand,
|
|
211
|
+
whyRecommended: `${srv.description} (Matched vertical touchpoints in ${matchedStoryIds.join(", ")}).`,
|
|
212
|
+
matchedStoryIds,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=mcp-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-registry.js","sourceRoot":"","sources":["../src/mcp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AC,CAAC;QAClC,UAAU,EAAE,GAAG,CAAC,EAAE;QAClB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,SAAS,EAAE,GAAG,CAAC,SAAS,KAAK,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO;QAC5E,kBAAkB,EAAE,GAAG,CAAC,iBAAiB;QACzC,cAAc,EAAE,GAAG,GAAG,CAAC,WAAW,qCAAqC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACrG,eAAe;KAChB,CAAC,CAAC,CAAC;AACR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specprism/registry-sync",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "SpecPrism Evergreen Registry Sync — Live OpenRouter AI catalog sanitizer and Official MCP Registry story recommender.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://spec-prism.app",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/orphik/specprism.git",
|
|
10
|
+
"directory": "packages/registry-sync"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.json",
|
|
32
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
33
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@specprism/core": "^1.0.1",
|
|
38
|
+
"@specprism/db": "^1.0.1",
|
|
39
|
+
"drizzle-orm": "^0.45.2",
|
|
40
|
+
"zod": "^3.24.4"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.15.0",
|
|
44
|
+
"typescript": "^5.8.3",
|
|
45
|
+
"vitest": "^3.1.4"
|
|
46
|
+
}
|
|
47
|
+
}
|