@happyvertical/sdk-mcp 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +135 -0
- package/dist/claude-context.d.ts +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.js +20 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +533 -0
- package/metadata.json +33 -0
- package/package.json +60 -0
package/AGENT.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @happyvertical/sdk-mcp
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN AGENT:GENERATED -->
|
|
4
|
+
## Purpose
|
|
5
|
+
MCP server for HAVE SDK - Routes queries to package experts using AGENT.md files
|
|
6
|
+
|
|
7
|
+
## Package Map
|
|
8
|
+
- Package: `@happyvertical/sdk-mcp`
|
|
9
|
+
- Hierarchy path: `@happyvertical/sdk > packages > sdk-mcp`
|
|
10
|
+
- Workspace position: `23 of 30` local packages
|
|
11
|
+
- Internal dependencies: `@happyvertical/ai`, `@happyvertical/files`, `@happyvertical/utils`
|
|
12
|
+
- Internal dependents: none
|
|
13
|
+
- Knowledge graph files: `AGENT.md`, `metadata.json`, `ecosystem-manifest.json`
|
|
14
|
+
|
|
15
|
+
## Build & Test
|
|
16
|
+
```bash
|
|
17
|
+
pnpm --filter @happyvertical/sdk-mcp build
|
|
18
|
+
pnpm --filter @happyvertical/sdk-mcp test
|
|
19
|
+
pnpm --filter @happyvertical/sdk-mcp clean
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Agent Correction Loops
|
|
23
|
+
- If module resolution or export errors mention a workspace dependency, build the dependency first (`pnpm --filter @happyvertical/ai build`, `pnpm --filter @happyvertical/files build`, `pnpm --filter @happyvertical/utils build`) and then rerun `pnpm --filter @happyvertical/sdk-mcp build`.
|
|
24
|
+
- If tests or exports fail after API, type, or bundle changes, run `pnpm --filter @happyvertical/sdk-mcp clean` followed by `pnpm --filter @happyvertical/sdk-mcp build` and `pnpm --filter @happyvertical/sdk-mcp test`.
|
|
25
|
+
- If failures span multiple packages or Turborepo ordering looks wrong, run `pnpm build` and `pnpm typecheck` from the repo root before retrying package-scoped commands.
|
|
26
|
+
|
|
27
|
+
## Ecosystem Relationships
|
|
28
|
+
- Provides: MCP server for HAVE SDK - Routes queries to package experts using AGENT.md files
|
|
29
|
+
- Implements: none
|
|
30
|
+
- Requires: @happyvertical/ai, @happyvertical/files, @happyvertical/utils, @modelcontextprotocol/sdk
|
|
31
|
+
- Stability: stable (Primary package surface is described as implemented and production-oriented.)
|
|
32
|
+
<!-- END AGENT:GENERATED -->
|
|
33
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @happyvertical/sdk-mcp
|
|
2
|
+
|
|
3
|
+
MCP server for the HAVE SDK that routes developer queries to package documentation. It scans each package's `AGENT.md` file at startup, builds a keyword-indexed registry, and exposes three MCP tools: `ask` (AI-powered Q&A), `list-packages`, and `get-docs`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install @happyvertical/sdk-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> Published to public npm. No scoped registry configuration is required.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### As an MCP Server
|
|
16
|
+
|
|
17
|
+
The package provides a stdio-based MCP server. Run it directly:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx sdk-mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or configure it in your MCP client (e.g., Claude Desktop) to launch as a subprocess.
|
|
24
|
+
|
|
25
|
+
### Claude Code Context CLI
|
|
26
|
+
|
|
27
|
+
Copy AGENT.md and metadata into your project's `.claude/` directory for AI-assisted development:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx have-sdk-mcp-context
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Environment Variables
|
|
34
|
+
|
|
35
|
+
The `ask` tool requires an AI provider. Set one of:
|
|
36
|
+
|
|
37
|
+
- `HAVE_AI_API_KEY` — Fallback API key for any provider
|
|
38
|
+
- `HAVE_AI_TYPE` — Provider type (`openai`, `anthropic`, `gemini`)
|
|
39
|
+
- `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GEMINI_API_KEY`
|
|
40
|
+
|
|
41
|
+
The `list-packages` and `get-docs` tools work without AI configuration.
|
|
42
|
+
|
|
43
|
+
## MCP Tools
|
|
44
|
+
|
|
45
|
+
### ask
|
|
46
|
+
|
|
47
|
+
Ask a question about the SDK. Routes to relevant packages via keyword matching and synthesizes a response using AI (top 3 matches).
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"query": "How do I send an email with an attachment?",
|
|
52
|
+
"packages": ["email", "messages"]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- `query` (required) — The question to ask
|
|
57
|
+
- `packages` (optional) — Explicit package names to consult instead of auto-routing
|
|
58
|
+
|
|
59
|
+
### list-packages
|
|
60
|
+
|
|
61
|
+
List all discovered SDK packages with descriptions and keywords. No parameters.
|
|
62
|
+
|
|
63
|
+
### get-docs
|
|
64
|
+
|
|
65
|
+
Get the full AGENT.md content for a specific package.
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"packageName": "ai"
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## How It Works
|
|
74
|
+
|
|
75
|
+
1. **Registry** — On first call, scans `packages/*/AGENT.md` and builds a `Map<string, PackageMetadata>` keyed by package name. Each entry includes the description (extracted from AGENT.md), keywords (from a static mapping in `registry.ts`), and the full documentation content.
|
|
76
|
+
|
|
77
|
+
2. **Routing** — Splits the user query into tokens and scores each package by keyword overlap (exact match = 10 pts, partial = 5 pts, name bonus = 15 pts). Packages below a minimum score threshold are excluded.
|
|
78
|
+
|
|
79
|
+
3. **Synthesis** — The `ask` tool loads AGENT.md for the top 3 matched packages, builds a system prompt with that context, and calls `@happyvertical/ai` to generate a response.
|
|
80
|
+
|
|
81
|
+
## Adding a New Package
|
|
82
|
+
|
|
83
|
+
1. Create an `AGENT.md` in the new package directory
|
|
84
|
+
2. Add a keyword entry in `src/registry.ts` (`PACKAGE_KEYWORDS`)
|
|
85
|
+
3. Rebuild: `pnpm run build`
|
|
86
|
+
|
|
87
|
+
The package will be discovered automatically on the next server startup.
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### Registry (`registry.ts`)
|
|
92
|
+
|
|
93
|
+
| Export | Description |
|
|
94
|
+
|--------|-------------|
|
|
95
|
+
| `PackageMetadata` | Interface: `name`, `path`, `description`, `claudeMd`, `keywords` |
|
|
96
|
+
| `PACKAGE_KEYWORDS` | Static keyword-to-package mapping used for routing |
|
|
97
|
+
| `buildPackageRegistry()` | Scans packages directory and returns cached `Map<string, PackageMetadata>` |
|
|
98
|
+
| `getPackage(name)` | Get metadata for a single package |
|
|
99
|
+
| `getAllPackages()` | Get all package metadata as an array |
|
|
100
|
+
| `getPackageDocs(name)` | Get raw AGENT.md content for a package |
|
|
101
|
+
| `clearCache()` | Clear the in-memory registry cache |
|
|
102
|
+
|
|
103
|
+
### Router (`router.ts`)
|
|
104
|
+
|
|
105
|
+
| Export | Description |
|
|
106
|
+
|--------|-------------|
|
|
107
|
+
| `PackageMatch` | Interface: `package`, `score`, `matchedKeywords` |
|
|
108
|
+
| `routeQuery(query, minScore?)` | Score and rank packages against a query string |
|
|
109
|
+
| `getPackagesByNames(names)` | Look up packages by explicit name list |
|
|
110
|
+
| `getTopPackages(query, limit?)` | Shorthand for `routeQuery` + slice |
|
|
111
|
+
|
|
112
|
+
### Tools (`tools/`)
|
|
113
|
+
|
|
114
|
+
| Export | Description |
|
|
115
|
+
|--------|-------------|
|
|
116
|
+
| `ask(input)` | AI-powered Q&A tool |
|
|
117
|
+
| `listPackages()` | List all packages |
|
|
118
|
+
| `getDocs(packageName)` | Get package documentation |
|
|
119
|
+
|
|
120
|
+
## Dependencies
|
|
121
|
+
|
|
122
|
+
- `@happyvertical/ai` — AI provider for the `ask` tool
|
|
123
|
+
- `@modelcontextprotocol/sdk` — MCP protocol implementation
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm run build # Build
|
|
129
|
+
pnpm test # Run tests
|
|
130
|
+
pnpm run dev # Watch mode (build + test)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, mkdirSync, copyFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const Dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const pkgRoot = join(Dirname, "../..");
|
|
7
|
+
const targetDir = join(process.cwd(), ".claude");
|
|
8
|
+
if (!existsSync(targetDir)) {
|
|
9
|
+
mkdirSync(targetDir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
const pkgName = "sdk-mcp";
|
|
12
|
+
const agentMdSrc = existsSync(join(pkgRoot, "AGENT.md")) ? join(pkgRoot, "AGENT.md") : join(pkgRoot, "CLAUDE.md");
|
|
13
|
+
const metaSrc = existsSync(join(pkgRoot, "metadata.json")) ? join(pkgRoot, "metadata.json") : join(pkgRoot, ".claude-meta.json");
|
|
14
|
+
if (existsSync(agentMdSrc)) {
|
|
15
|
+
copyFileSync(agentMdSrc, join(targetDir, `have-${pkgName}.md`));
|
|
16
|
+
}
|
|
17
|
+
if (existsSync(metaSrc)) {
|
|
18
|
+
copyFileSync(metaSrc, join(targetDir, `have-${pkgName}.meta.json`));
|
|
19
|
+
}
|
|
20
|
+
console.log(`✓ Installed @happyvertical/${pkgName} context to .claude/`);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { getAI } from "@happyvertical/ai";
|
|
6
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
const Filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const Dirname = dirname(Filename);
|
|
11
|
+
const PACKAGE_KEYWORDS = {
|
|
12
|
+
ai: [
|
|
13
|
+
"ai",
|
|
14
|
+
"llm",
|
|
15
|
+
"gpt",
|
|
16
|
+
"claude",
|
|
17
|
+
"openai",
|
|
18
|
+
"anthropic",
|
|
19
|
+
"model",
|
|
20
|
+
"completion",
|
|
21
|
+
"chat",
|
|
22
|
+
"embedding",
|
|
23
|
+
"gemini",
|
|
24
|
+
"bedrock",
|
|
25
|
+
"huggingface"
|
|
26
|
+
],
|
|
27
|
+
sql: [
|
|
28
|
+
"database",
|
|
29
|
+
"sql",
|
|
30
|
+
"sqlite",
|
|
31
|
+
"postgres",
|
|
32
|
+
"duckdb",
|
|
33
|
+
"query",
|
|
34
|
+
"table",
|
|
35
|
+
"schema",
|
|
36
|
+
"json"
|
|
37
|
+
],
|
|
38
|
+
files: [
|
|
39
|
+
"file",
|
|
40
|
+
"filesystem",
|
|
41
|
+
"read",
|
|
42
|
+
"write",
|
|
43
|
+
"download",
|
|
44
|
+
"upload",
|
|
45
|
+
"path",
|
|
46
|
+
"storage"
|
|
47
|
+
],
|
|
48
|
+
spider: [
|
|
49
|
+
"crawl",
|
|
50
|
+
"scrape",
|
|
51
|
+
"web",
|
|
52
|
+
"html",
|
|
53
|
+
"website",
|
|
54
|
+
"page",
|
|
55
|
+
"link",
|
|
56
|
+
"civicweb"
|
|
57
|
+
],
|
|
58
|
+
pdf: ["pdf", "document", "extract", "parse", "acrobat"],
|
|
59
|
+
ocr: ["ocr", "image", "text extraction", "tesseract", "vision"],
|
|
60
|
+
geo: ["location", "map", "coordinates", "geocode", "address", "gis"],
|
|
61
|
+
translator: ["translate", "language", "translation", "localization"],
|
|
62
|
+
weather: [
|
|
63
|
+
"weather",
|
|
64
|
+
"forecast",
|
|
65
|
+
"temperature",
|
|
66
|
+
"precipitation",
|
|
67
|
+
"conditions",
|
|
68
|
+
"wind",
|
|
69
|
+
"humidity",
|
|
70
|
+
"openweathermap",
|
|
71
|
+
"environment canada"
|
|
72
|
+
],
|
|
73
|
+
utils: ["id", "uuid", "slug", "date", "format", "utility", "helper"],
|
|
74
|
+
cache: ["cache", "caching", "redis", "memory", "store"],
|
|
75
|
+
logger: ["log", "logging", "logger", "debug", "error"],
|
|
76
|
+
documents: ["document processing", "content extraction", "analysis"],
|
|
77
|
+
email: [
|
|
78
|
+
"email",
|
|
79
|
+
"mail",
|
|
80
|
+
"smtp",
|
|
81
|
+
"imap",
|
|
82
|
+
"pop3",
|
|
83
|
+
"gmail",
|
|
84
|
+
"mailbox",
|
|
85
|
+
"send",
|
|
86
|
+
"receive",
|
|
87
|
+
"inbox",
|
|
88
|
+
"folder"
|
|
89
|
+
],
|
|
90
|
+
"github-actions": [
|
|
91
|
+
"github",
|
|
92
|
+
"actions",
|
|
93
|
+
"workflow",
|
|
94
|
+
"ci",
|
|
95
|
+
"cd",
|
|
96
|
+
"automation",
|
|
97
|
+
"issue",
|
|
98
|
+
"pr",
|
|
99
|
+
"pull request",
|
|
100
|
+
"triage"
|
|
101
|
+
],
|
|
102
|
+
directory: [
|
|
103
|
+
"directory",
|
|
104
|
+
"identity",
|
|
105
|
+
"provisioning",
|
|
106
|
+
"kanidm",
|
|
107
|
+
"stalwart",
|
|
108
|
+
"postgres",
|
|
109
|
+
"aws",
|
|
110
|
+
"iam",
|
|
111
|
+
"user",
|
|
112
|
+
"group",
|
|
113
|
+
"oauth",
|
|
114
|
+
"mail",
|
|
115
|
+
"domain",
|
|
116
|
+
"dkim",
|
|
117
|
+
"role",
|
|
118
|
+
"tenant"
|
|
119
|
+
],
|
|
120
|
+
analytics: [
|
|
121
|
+
"analytics",
|
|
122
|
+
"tracking",
|
|
123
|
+
"ga4",
|
|
124
|
+
"google analytics",
|
|
125
|
+
"plausible",
|
|
126
|
+
"metrics",
|
|
127
|
+
"dimensions",
|
|
128
|
+
"report",
|
|
129
|
+
"pageview",
|
|
130
|
+
"event",
|
|
131
|
+
"conversion",
|
|
132
|
+
"measurement protocol"
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
const packageCache = /* @__PURE__ */ new Map();
|
|
136
|
+
function getSDKRoot() {
|
|
137
|
+
return join(Dirname, "..", "..", "..");
|
|
138
|
+
}
|
|
139
|
+
function extractDescription(content) {
|
|
140
|
+
const purposeMatch = content.match(
|
|
141
|
+
/##\s+Purpose and Responsibilities\s+([^\n]+(?:\n(?!##)[^\n]+)*)/i
|
|
142
|
+
);
|
|
143
|
+
if (purposeMatch) {
|
|
144
|
+
const purpose = purposeMatch[1].trim().replace(/\n/g, " ").replace(/\s+/g, " ");
|
|
145
|
+
const firstSentence = purpose.match(/^[^.!?]+[.!?]/);
|
|
146
|
+
if (firstSentence) {
|
|
147
|
+
return firstSentence[0].trim();
|
|
148
|
+
}
|
|
149
|
+
return `${purpose.substring(0, 200).trim()}...`;
|
|
150
|
+
}
|
|
151
|
+
const lines = content.split("\n");
|
|
152
|
+
let foundTitle = false;
|
|
153
|
+
for (const line of lines) {
|
|
154
|
+
if (line.startsWith("# ") || line.startsWith("## ")) {
|
|
155
|
+
foundTitle = true;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (foundTitle && line.trim().length > 0 && !line.startsWith("#")) {
|
|
159
|
+
return line.trim();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return "No description available";
|
|
163
|
+
}
|
|
164
|
+
async function buildPackageRegistry() {
|
|
165
|
+
if (packageCache.size > 0) {
|
|
166
|
+
return packageCache;
|
|
167
|
+
}
|
|
168
|
+
const sdkRoot = getSDKRoot();
|
|
169
|
+
const packagesDir = join(sdkRoot, "packages");
|
|
170
|
+
try {
|
|
171
|
+
const entries = await readdir(packagesDir, { withFileTypes: true });
|
|
172
|
+
for (const entry of entries) {
|
|
173
|
+
if (!entry.isDirectory()) continue;
|
|
174
|
+
const packageName = entry.name;
|
|
175
|
+
const agentMdPath = join(packagesDir, packageName, "AGENT.md");
|
|
176
|
+
const legacyClaudePath = join(packagesDir, packageName, "CLAUDE.md");
|
|
177
|
+
try {
|
|
178
|
+
let agentMd;
|
|
179
|
+
try {
|
|
180
|
+
agentMd = await readFile(agentMdPath, "utf-8");
|
|
181
|
+
} catch {
|
|
182
|
+
agentMd = await readFile(legacyClaudePath, "utf-8");
|
|
183
|
+
}
|
|
184
|
+
const description = extractDescription(agentMd);
|
|
185
|
+
const keywords = PACKAGE_KEYWORDS[packageName] || [];
|
|
186
|
+
packageCache.set(packageName, {
|
|
187
|
+
name: packageName,
|
|
188
|
+
path: join(packagesDir, packageName),
|
|
189
|
+
description,
|
|
190
|
+
agentMd,
|
|
191
|
+
keywords
|
|
192
|
+
});
|
|
193
|
+
} catch (_error) {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return packageCache;
|
|
197
|
+
} catch (error) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`Failed to build package registry: ${error instanceof Error ? error.message : String(error)}`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function getPackage(name) {
|
|
204
|
+
const registry = await buildPackageRegistry();
|
|
205
|
+
return registry.get(name);
|
|
206
|
+
}
|
|
207
|
+
async function getAllPackages() {
|
|
208
|
+
const registry = await buildPackageRegistry();
|
|
209
|
+
return Array.from(registry.values());
|
|
210
|
+
}
|
|
211
|
+
async function getPackageDocs(name) {
|
|
212
|
+
const pkg = await getPackage(name);
|
|
213
|
+
return pkg?.agentMd;
|
|
214
|
+
}
|
|
215
|
+
function extractQueryKeywords(query) {
|
|
216
|
+
return query.toLowerCase().split(/\W+/).filter((word) => word.length > 2);
|
|
217
|
+
}
|
|
218
|
+
function calculateScore(queryKeywords, packageKeywords) {
|
|
219
|
+
const matched = [];
|
|
220
|
+
let score = 0;
|
|
221
|
+
for (const queryKeyword of queryKeywords) {
|
|
222
|
+
for (const packageKeyword of packageKeywords) {
|
|
223
|
+
if (queryKeyword === packageKeyword) {
|
|
224
|
+
score += 10;
|
|
225
|
+
matched.push(packageKeyword);
|
|
226
|
+
} else if (queryKeyword.includes(packageKeyword) || packageKeyword.includes(queryKeyword)) {
|
|
227
|
+
score += 5;
|
|
228
|
+
if (!matched.includes(packageKeyword)) {
|
|
229
|
+
matched.push(packageKeyword);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
for (const queryKeyword of queryKeywords) {
|
|
235
|
+
if (packageKeywords.some((pkg) => pkg.toLowerCase() === queryKeyword)) {
|
|
236
|
+
score += 15;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { score, matched };
|
|
240
|
+
}
|
|
241
|
+
async function routeQuery(query, minScore = 5) {
|
|
242
|
+
const packages = await getAllPackages();
|
|
243
|
+
const queryKeywords = extractQueryKeywords(query);
|
|
244
|
+
const matches = [];
|
|
245
|
+
for (const pkg of packages) {
|
|
246
|
+
const { score, matched } = calculateScore(queryKeywords, pkg.keywords);
|
|
247
|
+
if (score >= minScore) {
|
|
248
|
+
matches.push({
|
|
249
|
+
package: pkg,
|
|
250
|
+
score,
|
|
251
|
+
matchedKeywords: matched
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
matches.sort((a, b) => b.score - a.score);
|
|
256
|
+
return matches;
|
|
257
|
+
}
|
|
258
|
+
async function getPackagesByNames(names) {
|
|
259
|
+
const packages = await getAllPackages();
|
|
260
|
+
const nameSet = new Set(names.map((n) => n.toLowerCase()));
|
|
261
|
+
return packages.filter((pkg) => nameSet.has(pkg.name.toLowerCase()));
|
|
262
|
+
}
|
|
263
|
+
async function getAIClient() {
|
|
264
|
+
try {
|
|
265
|
+
return await getAI({});
|
|
266
|
+
} catch (error) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
`AI client initialization failed. Please configure AI provider using HAVE_AI_* environment variables. Error: ${error instanceof Error ? error.message : String(error)}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function buildContext(packages) {
|
|
273
|
+
if (packages.length === 0) {
|
|
274
|
+
return "No relevant packages found.";
|
|
275
|
+
}
|
|
276
|
+
const contextParts = [];
|
|
277
|
+
for (const pkg of packages) {
|
|
278
|
+
contextParts.push(
|
|
279
|
+
`## Package: @happyvertical/${pkg.name}
|
|
280
|
+
|
|
281
|
+
${pkg.agentMd}
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return contextParts.join("\n");
|
|
288
|
+
}
|
|
289
|
+
async function ask(input) {
|
|
290
|
+
const { query, packages: requestedPackages } = input;
|
|
291
|
+
try {
|
|
292
|
+
let packages;
|
|
293
|
+
if (requestedPackages && requestedPackages.length > 0) {
|
|
294
|
+
packages = await getPackagesByNames(requestedPackages);
|
|
295
|
+
if (packages.length === 0) {
|
|
296
|
+
return {
|
|
297
|
+
content: [
|
|
298
|
+
{
|
|
299
|
+
type: "text",
|
|
300
|
+
text: `None of the requested packages (${requestedPackages.join(", ")}) were found. Use list-packages to see available packages.`
|
|
301
|
+
}
|
|
302
|
+
],
|
|
303
|
+
isError: true
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
const matches = await routeQuery(query);
|
|
308
|
+
if (matches.length === 0) {
|
|
309
|
+
return {
|
|
310
|
+
content: [
|
|
311
|
+
{
|
|
312
|
+
type: "text",
|
|
313
|
+
text: `No relevant packages found for query: "${query}". Try using list-packages to browse available packages or specify packages explicitly.`
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
isError: false
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
packages = matches.slice(0, 3).map((m) => m.package);
|
|
320
|
+
}
|
|
321
|
+
const context = buildContext(packages);
|
|
322
|
+
const ai = await getAIClient();
|
|
323
|
+
const systemPrompt = `You are an expert SDK documentation assistant for the HAppy VErtical (HAVE) SDK.
|
|
324
|
+
You have access to the full documentation (AGENT.md files) for the following packages: ${packages.map((p) => `@happyvertical/${p.name}`).join(", ")}.
|
|
325
|
+
|
|
326
|
+
Your role is to:
|
|
327
|
+
1. Answer questions about the SDK using the provided package documentation
|
|
328
|
+
2. Provide code examples when relevant
|
|
329
|
+
3. Reference specific packages and documentation sections
|
|
330
|
+
4. Be concise but thorough
|
|
331
|
+
5. Include package names in your response (e.g., "@happyvertical/ai", "@happyvertical/sql")
|
|
332
|
+
|
|
333
|
+
Use the documentation provided below to answer the user's question accurately.
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
${context}
|
|
337
|
+
---`;
|
|
338
|
+
const response = await ai.chat(
|
|
339
|
+
[
|
|
340
|
+
{ role: "system", content: systemPrompt },
|
|
341
|
+
{ role: "user", content: query }
|
|
342
|
+
],
|
|
343
|
+
{
|
|
344
|
+
temperature: 0.7,
|
|
345
|
+
maxTokens: 2e3
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
const packageList = packages.map((p) => `@happyvertical/${p.name}`).join(", ");
|
|
349
|
+
const footer = `
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
*Consulted packages: ${packageList}*`;
|
|
353
|
+
return {
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
type: "text",
|
|
357
|
+
text: response.content + footer
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
};
|
|
361
|
+
} catch (error) {
|
|
362
|
+
return {
|
|
363
|
+
content: [
|
|
364
|
+
{
|
|
365
|
+
type: "text",
|
|
366
|
+
text: `Error processing query: ${error instanceof Error ? error.message : String(error)}`
|
|
367
|
+
}
|
|
368
|
+
],
|
|
369
|
+
isError: true
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
async function getDocs(packageName) {
|
|
374
|
+
const docs = await getPackageDocs(packageName);
|
|
375
|
+
if (!docs) {
|
|
376
|
+
return {
|
|
377
|
+
content: [
|
|
378
|
+
{
|
|
379
|
+
type: "text",
|
|
380
|
+
text: `Package "${packageName}" not found. Use list-packages to see available packages.`
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
isError: true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
content: [
|
|
388
|
+
{
|
|
389
|
+
type: "text",
|
|
390
|
+
text: docs
|
|
391
|
+
}
|
|
392
|
+
]
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
async function listPackages() {
|
|
396
|
+
const packages = await getAllPackages();
|
|
397
|
+
return {
|
|
398
|
+
content: [
|
|
399
|
+
{
|
|
400
|
+
type: "text",
|
|
401
|
+
text: JSON.stringify(
|
|
402
|
+
{
|
|
403
|
+
packages: packages.map((pkg) => ({
|
|
404
|
+
name: pkg.name,
|
|
405
|
+
description: pkg.description,
|
|
406
|
+
keywords: pkg.keywords
|
|
407
|
+
})),
|
|
408
|
+
total: packages.length
|
|
409
|
+
},
|
|
410
|
+
null,
|
|
411
|
+
2
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
class SDKMCPServer {
|
|
418
|
+
server;
|
|
419
|
+
constructor() {
|
|
420
|
+
this.server = new Server(
|
|
421
|
+
{
|
|
422
|
+
name: "happyvertical-sdk-mcp",
|
|
423
|
+
version: "0.1.0"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
capabilities: {
|
|
427
|
+
tools: {}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
);
|
|
431
|
+
this.setupToolHandlers();
|
|
432
|
+
this.setupErrorHandling();
|
|
433
|
+
}
|
|
434
|
+
setupToolHandlers() {
|
|
435
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
436
|
+
tools: [
|
|
437
|
+
{
|
|
438
|
+
name: "ask",
|
|
439
|
+
description: "Ask a question about the HAVE SDK. Automatically routes your query to relevant package experts (AGENT.md files) and synthesizes a response using AI.",
|
|
440
|
+
inputSchema: {
|
|
441
|
+
type: "object",
|
|
442
|
+
properties: {
|
|
443
|
+
query: {
|
|
444
|
+
type: "string",
|
|
445
|
+
description: "Your question about SDK usage or capabilities"
|
|
446
|
+
},
|
|
447
|
+
packages: {
|
|
448
|
+
type: "array",
|
|
449
|
+
items: { type: "string" },
|
|
450
|
+
description: 'Optional: Specific packages to consult (e.g., ["ai", "sql"])'
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
required: ["query"]
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: "list-packages",
|
|
458
|
+
description: "List all available SDK packages with their descriptions and keywords",
|
|
459
|
+
inputSchema: {
|
|
460
|
+
type: "object",
|
|
461
|
+
properties: {}
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
name: "get-docs",
|
|
466
|
+
description: "Get the full AGENT.md documentation for a specific package",
|
|
467
|
+
inputSchema: {
|
|
468
|
+
type: "object",
|
|
469
|
+
properties: {
|
|
470
|
+
packageName: {
|
|
471
|
+
type: "string",
|
|
472
|
+
description: 'Name of the package (e.g., "ai", "sql", "spider")'
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
required: ["packageName"]
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
]
|
|
479
|
+
}));
|
|
480
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
481
|
+
try {
|
|
482
|
+
switch (request.params.name) {
|
|
483
|
+
case "ask": {
|
|
484
|
+
const input = request.params.arguments ?? {};
|
|
485
|
+
return await ask(input);
|
|
486
|
+
}
|
|
487
|
+
case "list-packages": {
|
|
488
|
+
return await listPackages();
|
|
489
|
+
}
|
|
490
|
+
case "get-docs": {
|
|
491
|
+
const args = request.params.arguments ?? {};
|
|
492
|
+
return await getDocs(args.packageName);
|
|
493
|
+
}
|
|
494
|
+
default:
|
|
495
|
+
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
496
|
+
}
|
|
497
|
+
} catch (error) {
|
|
498
|
+
return {
|
|
499
|
+
content: [
|
|
500
|
+
{
|
|
501
|
+
type: "text",
|
|
502
|
+
text: `Error executing tool: ${error instanceof Error ? error.message : String(error)}`
|
|
503
|
+
}
|
|
504
|
+
],
|
|
505
|
+
isError: true
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
setupErrorHandling() {
|
|
511
|
+
this.server.onerror = (error) => {
|
|
512
|
+
console.error("[MCP Error]", error);
|
|
513
|
+
};
|
|
514
|
+
process.on("SIGINT", async () => {
|
|
515
|
+
await this.server.close();
|
|
516
|
+
process.exit(0);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
async run() {
|
|
520
|
+
const transport = new StdioServerTransport();
|
|
521
|
+
await this.server.connect(transport);
|
|
522
|
+
console.error("HappyVertical SDK MCP Server running on stdio");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const server = new SDKMCPServer();
|
|
526
|
+
server.run().catch((error) => {
|
|
527
|
+
console.error("Fatal error:", error);
|
|
528
|
+
process.exit(1);
|
|
529
|
+
});
|
|
530
|
+
const PACKAGE_VERSION_INITIALIZED = true;
|
|
531
|
+
export {
|
|
532
|
+
PACKAGE_VERSION_INITIALIZED
|
|
533
|
+
};
|
package/metadata.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@happyvertical/sdk-mcp",
|
|
3
|
+
"path": "packages/sdk-mcp",
|
|
4
|
+
"position": {
|
|
5
|
+
"index": 23,
|
|
6
|
+
"count": 30
|
|
7
|
+
},
|
|
8
|
+
"description": "MCP server for HAVE SDK - Routes queries to package experts using AGENT.md files",
|
|
9
|
+
"provides": [
|
|
10
|
+
"MCP server for HAVE SDK - Routes queries to package experts using AGENT.md files"
|
|
11
|
+
],
|
|
12
|
+
"implements": [],
|
|
13
|
+
"requires": {
|
|
14
|
+
"workspace": [
|
|
15
|
+
"@happyvertical/ai",
|
|
16
|
+
"@happyvertical/files",
|
|
17
|
+
"@happyvertical/utils"
|
|
18
|
+
],
|
|
19
|
+
"externalHappyVertical": [],
|
|
20
|
+
"external": [
|
|
21
|
+
"@modelcontextprotocol/sdk"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"dependents": [],
|
|
25
|
+
"stability": {
|
|
26
|
+
"level": "stable",
|
|
27
|
+
"reason": "Primary package surface is described as implemented and production-oriented."
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"sdk",
|
|
31
|
+
"mcp"
|
|
32
|
+
]
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@happyvertical/sdk-mcp",
|
|
3
|
+
"version": "0.74.8",
|
|
4
|
+
"description": "MCP server for HAVE SDK - Routes queries to package experts using AGENT.md files",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"sdk-mcp": "./dist/index.js",
|
|
10
|
+
"have-sdk-mcp-context": "./dist/cli/claude-context.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"AGENT.md",
|
|
23
|
+
"metadata.json"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org",
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/happyvertical/sdk.git",
|
|
32
|
+
"directory": "packages/sdk-mcp"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/happyvertical/sdk/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/happyvertical/sdk/tree/main/packages/sdk-mcp#readme",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@modelcontextprotocol/sdk": "1.29.0",
|
|
41
|
+
"@happyvertical/utils": "0.74.8",
|
|
42
|
+
"@happyvertical/ai": "0.74.8",
|
|
43
|
+
"@happyvertical/files": "0.74.8"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "25.0.10",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vite": "7.3.2",
|
|
49
|
+
"vite-plugin-dts": "4.5.4",
|
|
50
|
+
"vitest": "^4.1.5"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"test": "npx vitest run --passWithNoTests",
|
|
54
|
+
"test:watch": "npx vitest",
|
|
55
|
+
"build": "vite build",
|
|
56
|
+
"build:watch": "vite build --watch",
|
|
57
|
+
"clean": "rm -rf dist",
|
|
58
|
+
"dev": "npm run build:watch & npm run test:watch"
|
|
59
|
+
}
|
|
60
|
+
}
|