@hexagen-monaco/sync 0.5.2 → 0.6.0
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/dist/cli.js +1191 -389
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/fs-utils.d.ts +13 -0
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/generators/apps-framework-templates.d.ts +2 -1
- package/dist/generators/apps-framework-templates.d.ts.map +1 -1
- package/dist/generators/apps.d.ts.map +1 -1
- package/dist/generators/architecture-files.d.ts.map +1 -1
- package/dist/generators/barrels/recursive.d.ts.map +1 -1
- package/dist/generators/cross-context.d.ts +5 -0
- package/dist/generators/cross-context.d.ts.map +1 -0
- package/dist/generators/eslint.d.ts +3 -1
- package/dist/generators/eslint.d.ts.map +1 -1
- package/dist/generators/layer-folders.d.ts.map +1 -1
- package/dist/generators/port-analyzer.d.ts +38 -4
- package/dist/generators/port-analyzer.d.ts.map +1 -1
- package/dist/generators/root-file-templates.d.ts +3 -3
- package/dist/generators/root-file-templates.d.ts.map +1 -1
- package/dist/generators/shared-kernel.d.ts +23 -0
- package/dist/generators/shared-kernel.d.ts.map +1 -0
- package/dist/generators/stubs.d.ts +13 -0
- package/dist/generators/stubs.d.ts.map +1 -1
- package/dist/index.js +950 -172
- package/dist/index.js.map +1 -1
- package/dist/scope-filter.d.ts +35 -0
- package/dist/scope-filter.d.ts.map +1 -0
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/templates/adobe-creative-production/manifest.json +2 -0
- package/dist/templates/adobe-express/manifest.json +2 -0
- package/dist/templates/adobe-firefly-composite/manifest.json +2 -0
- package/dist/templates/adobe-firefly-content-tagging/manifest.json +2 -0
- package/dist/templates/adobe-firefly-core/manifest.json +2 -0
- package/dist/templates/adobe-firefly-custom-models/manifest.json +2 -0
- package/dist/templates/adobe-firefly-generate/manifest.json +2 -0
- package/dist/templates/adobe-firefly-media/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-azure/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-gcs/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-s3/manifest.json +2 -0
- package/dist/templates/adobe-firefly-upscale/manifest.json +2 -0
- package/dist/templates/adobe-illustrator/manifest.json +2 -0
- package/dist/templates/adobe-ims-spa/manifest.json +2 -0
- package/dist/templates/adobe-indesign/manifest.json +2 -0
- package/dist/templates/adobe-lightroom/manifest.json +2 -0
- package/dist/templates/adobe-photoshop/manifest.json +2 -0
- package/dist/templates/adobe-substance-3d/manifest.json +2 -0
- package/dist/templates/auth-mock/manifest.json +2 -0
- package/dist/templates/bedrock-agentcore-runtime/manifest.json +10 -2
- package/dist/templates/bedrock-agentcore-services/manifest.json +38 -9
- package/dist/templates/better-auth/manifest.json +2 -0
- package/dist/templates/bullmq/manifest.json +2 -0
- package/dist/templates/ci-github-actions/README.md +7 -0
- package/dist/templates/ci-github-actions/files/.github/dependabot.yml +16 -4
- package/dist/templates/ci-github-actions/files/.github/workflows/ci.yml +7 -3
- package/dist/templates/ci-github-actions/files/.github/workflows/preview.yml +20 -2
- package/dist/templates/ci-github-actions/manifest.json +26 -6
- package/dist/templates/clerk/manifest.json +2 -0
- package/dist/templates/design-system/manifest.json +14 -3
- package/dist/templates/docker/manifest.json +2 -0
- package/dist/templates/error-handling/manifest.json +2 -0
- package/dist/templates/eslint-no-console/manifest.json +2 -0
- package/dist/templates/github-oauth/manifest.json +2 -0
- package/dist/templates/google-oauth/manifest.json +2 -0
- package/dist/templates/langgraph/manifest.json +62 -15
- package/dist/templates/llm-adapter/manifest.json +2 -0
- package/dist/templates/magic-link/manifest.json +2 -0
- package/dist/templates/mcp-server/README.md +49 -0
- package/dist/templates/mcp-server/files/.env.mcp.example +6 -0
- package/dist/templates/mcp-server/files/.mcp.json.example +8 -0
- package/dist/templates/mcp-server/files/bin/cli.ts +15 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/prompts/example.prompt.ts +32 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/register-all.ts +11 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/tool-registry.test.ts +67 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/tool-registry.ts +45 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/resources/example.resource.ts +28 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/sdk.ts +41 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/server.ts +52 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/tools/example.tool.test.ts +31 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/tools/example.tool.ts +74 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/transport/register-transports.ts +15 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/transport/stdio.ts +14 -0
- package/dist/templates/mcp-server/manifest.json +68 -0
- package/dist/templates/mcp-server-http/README.md +98 -0
- package/dist/templates/mcp-server-http/files/.env.mcp-http.example +22 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/bearer.test.ts +54 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/bearer.ts +49 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/oauth.test.ts +50 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/oauth.ts +53 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/guard.test.ts +75 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/guard.ts +26 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/transport/http.ts +94 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/transport/register-transports.ts +15 -0
- package/dist/templates/mcp-server-http/manifest.json +56 -0
- package/dist/templates/microsoft-entra/manifest.json +2 -0
- package/dist/templates/nextauth/manifest.json +2 -0
- package/dist/templates/observability/manifest.json +10 -2
- package/dist/templates/rate-limiting/manifest.json +2 -0
- package/dist/templates/shared-types/manifest.json +2 -0
- package/dist/templates/supabase/manifest.json +2 -0
- package/dist/templates/supabase-auth/manifest.json +2 -0
- package/dist/types/manifest/apps.d.ts +12 -1
- package/dist/types/manifest/apps.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
"name": "Google OAuth 2.0",
|
|
4
4
|
"description": "Server-side Google OAuth 2.0: authorization code flow, userinfo fetch, AES-256-GCM session cookie, optional hosted-domain restriction, and a root middleware that protects configured paths while still honouring AUTH_MODE=mock as a dev short-circuit.",
|
|
5
5
|
"version": "2.0.0",
|
|
6
|
+
"provides": "platform.auth",
|
|
7
|
+
"scope": "project",
|
|
6
8
|
"requires": ["shared-types", "auth-mock", "env-setup"],
|
|
7
9
|
"conflicts": [
|
|
8
10
|
"nextauth",
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"id": "langgraph",
|
|
3
3
|
"name": "LangGraph",
|
|
4
4
|
"description": "Hexagonal LangGraph integration: typed AgentGraphPort, shared GraphState, node files, conditional edge routing, swap-by-env checkpointers (memory/supabase/redis/postgres), and Next.js routes for invoke / optional streaming / optional human-in-the-loop resume. Comes with one of two working example graphs (simple-chain or research-agent) so the wiring is end-to-end out of the box.",
|
|
5
|
+
"provides": "agent.out-adapter",
|
|
6
|
+
"scope": "context",
|
|
5
7
|
"version": "1.0.0",
|
|
6
8
|
"requires": ["env-setup", "llm-adapter"],
|
|
7
9
|
"conflicts": [],
|
|
@@ -59,63 +61,108 @@
|
|
|
59
61
|
".env.langgraph.example",
|
|
60
62
|
{
|
|
61
63
|
"path": "src/infrastructure/langgraph/nodes/input-processor.node.ts",
|
|
62
|
-
"when": {
|
|
64
|
+
"when": {
|
|
65
|
+
"answer": "graph_type",
|
|
66
|
+
"equals": "simple-chain"
|
|
67
|
+
}
|
|
63
68
|
},
|
|
64
69
|
{
|
|
65
70
|
"path": "src/infrastructure/langgraph/nodes/llm-call.node.ts",
|
|
66
|
-
"when": {
|
|
71
|
+
"when": {
|
|
72
|
+
"answer": "graph_type",
|
|
73
|
+
"equals": "simple-chain"
|
|
74
|
+
}
|
|
67
75
|
},
|
|
68
76
|
{
|
|
69
77
|
"path": "src/infrastructure/langgraph/nodes/output-formatter.node.ts",
|
|
70
|
-
"when": {
|
|
78
|
+
"when": {
|
|
79
|
+
"answer": "graph_type",
|
|
80
|
+
"equals": "simple-chain"
|
|
81
|
+
}
|
|
71
82
|
},
|
|
72
83
|
{
|
|
73
84
|
"path": "src/infrastructure/langgraph/graphs/simple-chain.graph.ts",
|
|
74
|
-
"when": {
|
|
85
|
+
"when": {
|
|
86
|
+
"answer": "graph_type",
|
|
87
|
+
"equals": "simple-chain"
|
|
88
|
+
}
|
|
75
89
|
},
|
|
76
90
|
{
|
|
77
91
|
"path": "src/infrastructure/langgraph/nodes/planner.node.ts",
|
|
78
|
-
"when": {
|
|
92
|
+
"when": {
|
|
93
|
+
"answer": "graph_type",
|
|
94
|
+
"equals": "research-agent"
|
|
95
|
+
}
|
|
79
96
|
},
|
|
80
97
|
{
|
|
81
98
|
"path": "src/infrastructure/langgraph/nodes/researcher.node.ts",
|
|
82
|
-
"when": {
|
|
99
|
+
"when": {
|
|
100
|
+
"answer": "graph_type",
|
|
101
|
+
"equals": "research-agent"
|
|
102
|
+
}
|
|
83
103
|
},
|
|
84
104
|
{
|
|
85
105
|
"path": "src/infrastructure/langgraph/nodes/synthesiser.node.ts",
|
|
86
|
-
"when": {
|
|
106
|
+
"when": {
|
|
107
|
+
"answer": "graph_type",
|
|
108
|
+
"equals": "research-agent"
|
|
109
|
+
}
|
|
87
110
|
},
|
|
88
111
|
{
|
|
89
112
|
"path": "src/infrastructure/langgraph/graphs/research-agent.graph.ts",
|
|
90
|
-
"when": {
|
|
113
|
+
"when": {
|
|
114
|
+
"answer": "graph_type",
|
|
115
|
+
"equals": "research-agent"
|
|
116
|
+
}
|
|
91
117
|
},
|
|
92
118
|
{
|
|
93
119
|
"path": "src/infrastructure/langgraph/checkpointers/supabase-checkpointer.ts",
|
|
94
|
-
"when": {
|
|
120
|
+
"when": {
|
|
121
|
+
"answer": "checkpointing",
|
|
122
|
+
"equals": "supabase"
|
|
123
|
+
}
|
|
95
124
|
},
|
|
96
125
|
{
|
|
97
126
|
"path": "src/infrastructure/langgraph/checkpointers/redis-checkpointer.ts",
|
|
98
|
-
"when": {
|
|
127
|
+
"when": {
|
|
128
|
+
"answer": "checkpointing",
|
|
129
|
+
"equals": "redis"
|
|
130
|
+
}
|
|
99
131
|
},
|
|
100
132
|
{
|
|
101
133
|
"path": "src/infrastructure/langgraph/checkpointers/postgres-checkpointer.ts",
|
|
102
|
-
"when": {
|
|
134
|
+
"when": {
|
|
135
|
+
"answer": "checkpointing",
|
|
136
|
+
"equals": "postgres"
|
|
137
|
+
}
|
|
103
138
|
},
|
|
104
139
|
{
|
|
105
140
|
"path": "src/infrastructure/langgraph/streaming/token-stream.ts",
|
|
106
|
-
"when": {
|
|
141
|
+
"when": {
|
|
142
|
+
"answer": "streaming",
|
|
143
|
+
"equals": true
|
|
144
|
+
}
|
|
107
145
|
},
|
|
108
146
|
{
|
|
109
147
|
"path": "app/api/agent/stream/route.ts",
|
|
110
|
-
"when": {
|
|
148
|
+
"when": {
|
|
149
|
+
"answer": "streaming",
|
|
150
|
+
"equals": true
|
|
151
|
+
}
|
|
111
152
|
},
|
|
112
153
|
{
|
|
113
154
|
"path": "src/infrastructure/langgraph/nodes/human-review.node.ts",
|
|
114
|
-
"when": {
|
|
155
|
+
"when": {
|
|
156
|
+
"answer": "human_in_loop",
|
|
157
|
+
"equals": true
|
|
158
|
+
}
|
|
115
159
|
},
|
|
116
160
|
{
|
|
117
161
|
"path": "app/api/agent/resume/route.ts",
|
|
118
|
-
"when": {
|
|
162
|
+
"when": {
|
|
163
|
+
"answer": "human_in_loop",
|
|
164
|
+
"equals": true
|
|
165
|
+
}
|
|
119
166
|
}
|
|
120
167
|
],
|
|
121
168
|
"checklist": [
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
"name": "LLM Adapter",
|
|
4
4
|
"description": "Typed port interface, provider adapters (xAI, OpenAI, Anthropic, Ollama, Azure OpenAI), model constants, reasoning routing, retry logic, structured output",
|
|
5
5
|
"version": "1.0.0",
|
|
6
|
+
"provides": "llm.out-adapter",
|
|
7
|
+
"scope": "context",
|
|
6
8
|
"requires": ["env-setup", "error-handling"],
|
|
7
9
|
"conflicts": [],
|
|
8
10
|
"questions": [
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
"name": "Magic Link (Passwordless)",
|
|
4
4
|
"description": "HMAC-SHA256 signed single-use tokens, Resend/Nodemailer transport, 10k-entry LRU replay store, AES-256-GCM stateless session cookie, and a root middleware that protects configured paths while still honouring AUTH_MODE=mock as a dev short-circuit.",
|
|
5
5
|
"version": "2.0.0",
|
|
6
|
+
"provides": "platform.auth",
|
|
7
|
+
"scope": "project",
|
|
6
8
|
"requires": ["shared-types", "auth-mock", "env-setup"],
|
|
7
9
|
"conflicts": [
|
|
8
10
|
"nextauth",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# `mcp-server` — MCP Server (stdio) add-on template
|
|
2
|
+
|
|
3
|
+
Exposes the generated project's **application use-cases as MCP tools** over stdio,
|
|
4
|
+
so any MCP client (Claude Desktop/Code, IDE agents, an AgentCore Gateway, a
|
|
5
|
+
LangGraph tool node) can call them. An MCP tool is an **inbound adapter** over a
|
|
6
|
+
use-case you already have — no business logic moves into it.
|
|
7
|
+
|
|
8
|
+
Design intent: `docs/planning/generator-templates/18-mcp-server.md`. Requires
|
|
9
|
+
`env-setup`; soft-pairs with `error-handling` + `observability`.
|
|
10
|
+
|
|
11
|
+
## What it scaffolds
|
|
12
|
+
|
|
13
|
+
| File | Purpose |
|
|
14
|
+
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `src/infrastructure/mcp/sdk.ts` | Dynamic `import()` of `@modelcontextprotocol/sdk` (ADR-0010) |
|
|
16
|
+
| `src/infrastructure/mcp/server.ts` | Composition root: a `registerTransport(factory)` seam + `startServer()` |
|
|
17
|
+
| `src/infrastructure/mcp/transport/stdio.ts` | stdio transport **factory** |
|
|
18
|
+
| `src/infrastructure/mcp/transport/register-transports.ts` | Static transport registrations (base: stdio) — the `-http` addon extends this, never `server.ts` |
|
|
19
|
+
| `src/infrastructure/mcp/registry/tool-registry.ts` | `registerTool` seam + `applyTools()` |
|
|
20
|
+
| `src/infrastructure/mcp/registry/register-all.ts` | Static tool registrations |
|
|
21
|
+
| `src/infrastructure/mcp/tools/example.tool.ts` | Worked tool: input validation, use-case call, **explicit `Result`→MCP mapping (incl. error path)**, `dry_run` |
|
|
22
|
+
| `bin/cli.ts`, `.mcp.json.example`, `.env.mcp.example` | Entry point + client/env config |
|
|
23
|
+
| `resources/`, `prompts/` (opt-in) | Read-only resource + reusable prompt stubs |
|
|
24
|
+
| `*.test.ts` | `node:test` scaffolds — emitted **only under `--with-tests`** |
|
|
25
|
+
|
|
26
|
+
Everything under `infrastructure/mcp/**` is `@hexagen-server-only` (ADR-0037): it
|
|
27
|
+
holds credentials + privileged use-cases and must never reach a client bundle.
|
|
28
|
+
|
|
29
|
+
## Adding a tool
|
|
30
|
+
|
|
31
|
+
1. Copy `tools/example.tool.ts`, wrap your use-case, and **keep the explicit
|
|
32
|
+
error mapping + `dry_run`** — that example is the pattern every tool inherits.
|
|
33
|
+
2. Add one import + one `registerTool(...)` line in `registry/register-all.ts`.
|
|
34
|
+
|
|
35
|
+
(Static registration by design: the template engine can't codegen a loop over a
|
|
36
|
+
selected tool set, so the list is hand-maintained.)
|
|
37
|
+
|
|
38
|
+
## Transports
|
|
39
|
+
|
|
40
|
+
The base ships **stdio** — the secure local default (a subprocess of a trusted
|
|
41
|
+
client, no network surface). For network access, install the **`mcp-server-http`**
|
|
42
|
+
addon: it registers a `streamable-http` transport via `register-transports.ts`
|
|
43
|
+
(the factory seam), so it never rewrites `server.ts`. HTTP is always authenticated.
|
|
44
|
+
|
|
45
|
+
## Setup
|
|
46
|
+
|
|
47
|
+
`hexagen templates info mcp-server` for the checklist. In short: `npm install
|
|
48
|
+
@modelcontextprotocol/sdk zod`, set `MCP_SERVER_NAME`, then verify with
|
|
49
|
+
`npx @modelcontextprotocol/inspector npx tsx bin/cli.ts`.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @hexagen-server-only — MCP server entry point.
|
|
3
|
+
// Run: npx tsx bin/cli.ts (or build → node dist/bin/cli.js)
|
|
4
|
+
//
|
|
5
|
+
// The side-effect imports populate the tool + transport registries before the
|
|
6
|
+
// server starts; order doesn't matter between them, but both must precede
|
|
7
|
+
// startServer().
|
|
8
|
+
import "../src/infrastructure/mcp/registry/register-all.js";
|
|
9
|
+
import "../src/infrastructure/mcp/transport/register-transports.js";
|
|
10
|
+
import { startServer } from "../src/infrastructure/mcp/server.js";
|
|
11
|
+
|
|
12
|
+
startServer().catch((error: unknown) => {
|
|
13
|
+
console.error("[mcp] failed to start:", error);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
/**
|
|
3
|
+
* Example MCP prompt — a reusable, named message template a client can invoke.
|
|
4
|
+
* A worked stub: wire it onto the server from your composition root and adapt
|
|
5
|
+
* the messages to your domain.
|
|
6
|
+
*/
|
|
7
|
+
import type { McpServerLike } from "../sdk.js";
|
|
8
|
+
|
|
9
|
+
type PromptCapableServer = McpServerLike & {
|
|
10
|
+
registerPrompt?: (
|
|
11
|
+
name: string,
|
|
12
|
+
config: { description: string },
|
|
13
|
+
handler: () => {
|
|
14
|
+
messages: Array<{ role: string; content: { type: "text"; text: string } }>;
|
|
15
|
+
},
|
|
16
|
+
) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function registerExamplePrompt(server: McpServerLike): void {
|
|
20
|
+
(server as PromptCapableServer).registerPrompt?.(
|
|
21
|
+
"example",
|
|
22
|
+
{ description: "Replace with a reusable prompt for your domain." },
|
|
23
|
+
() => ({
|
|
24
|
+
messages: [
|
|
25
|
+
{
|
|
26
|
+
role: "user",
|
|
27
|
+
content: { type: "text", text: "Summarize the latest changes." },
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
/**
|
|
3
|
+
* Static tool registrations. Add a real tool with one import + one
|
|
4
|
+
* `registerTool(...)` line below — copy `tools/example.tool.ts` as a starting
|
|
5
|
+
* point. The template engine can't codegen a loop over a selected tool set, so
|
|
6
|
+
* this list is yours to extend by hand.
|
|
7
|
+
*/
|
|
8
|
+
import { registerTool } from "./tool-registry.js";
|
|
9
|
+
import { exampleTool } from "../tools/example.tool.js";
|
|
10
|
+
|
|
11
|
+
registerTool(exampleTool);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
registerTool,
|
|
7
|
+
getRegisteredTools,
|
|
8
|
+
applyTools,
|
|
9
|
+
} from "./tool-registry.js";
|
|
10
|
+
import type { RegisteredTool } from "./tool-registry.js";
|
|
11
|
+
import type { McpServerLike } from "../sdk.js";
|
|
12
|
+
|
|
13
|
+
const toolResult = async () => ({
|
|
14
|
+
content: [{ type: "text" as const, text: "ok" }],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("tool-registry", () => {
|
|
18
|
+
it("registers a tool and exposes it via getRegisteredTools", () => {
|
|
19
|
+
const before = getRegisteredTools().length;
|
|
20
|
+
const tool: RegisteredTool = {
|
|
21
|
+
name: "sample",
|
|
22
|
+
description: "test",
|
|
23
|
+
inputSchema: {},
|
|
24
|
+
handler: toolResult,
|
|
25
|
+
};
|
|
26
|
+
registerTool(tool);
|
|
27
|
+
assert.equal(getRegisteredTools().length, before + 1);
|
|
28
|
+
assert.ok(getRegisteredTools().some((t) => t.name === "sample"));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("applies a registered tool onto the server with name, config, and handler", () => {
|
|
32
|
+
// Self-contained: register a uniquely-named tool here rather than relying on
|
|
33
|
+
// another test's registration leaking through the module-level registry.
|
|
34
|
+
registerTool({
|
|
35
|
+
name: "applied-check",
|
|
36
|
+
description: "desc",
|
|
37
|
+
inputSchema: { x: {} },
|
|
38
|
+
handler: toolResult,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Mock the full registerTool(name, config, handler) contract — so the test
|
|
42
|
+
// fails if applyTools ever stops passing the config or handler.
|
|
43
|
+
const calls: Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
hasConfig: boolean;
|
|
46
|
+
hasHandler: boolean;
|
|
47
|
+
}> = [];
|
|
48
|
+
const server: McpServerLike = {
|
|
49
|
+
registerTool: (name, config, handler) => {
|
|
50
|
+
calls.push({
|
|
51
|
+
name,
|
|
52
|
+
hasConfig:
|
|
53
|
+
typeof config.description === "string" && !!config.inputSchema,
|
|
54
|
+
hasHandler: typeof handler === "function",
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
connect: async () => {},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
applyTools(server);
|
|
61
|
+
|
|
62
|
+
const applied = calls.find((c) => c.name === "applied-check");
|
|
63
|
+
assert.ok(applied, "the registered tool was applied to the server");
|
|
64
|
+
assert.ok(applied.hasConfig, "config (description + inputSchema) was passed");
|
|
65
|
+
assert.ok(applied.hasHandler, "handler was passed");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @hexagen-server-only — privileged tool surface; never ship to a client bundle (ADR-0037).
|
|
2
|
+
/**
|
|
3
|
+
* The tool-registration seam. Tools are declared statically (see
|
|
4
|
+
* `register-all.ts`) by calling `registerTool(...)`; the composition root then
|
|
5
|
+
* `applyTools()` them onto the dynamically-loaded `McpServer`. Decoupling the
|
|
6
|
+
* declaration from the server instance keeps `register-all.ts` a flat, loop-free
|
|
7
|
+
* list (the template engine can't codegen a loop) and lets you add a tool with
|
|
8
|
+
* one import + one `registerTool(...)` line.
|
|
9
|
+
*/
|
|
10
|
+
import type { McpServerLike } from "../sdk.js";
|
|
11
|
+
|
|
12
|
+
/** An MCP tool result: text content, with `isError` set on a failure. */
|
|
13
|
+
export interface ToolResult {
|
|
14
|
+
content: Array<{ type: "text"; text: string }>;
|
|
15
|
+
isError?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RegisteredTool {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
/** A zod raw shape (`{ field: z.string(), ... }`) describing the tool input. */
|
|
22
|
+
inputSchema: Record<string, unknown>;
|
|
23
|
+
handler: (input: Record<string, unknown>) => Promise<ToolResult>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const tools: RegisteredTool[] = [];
|
|
27
|
+
|
|
28
|
+
export function registerTool(tool: RegisteredTool): void {
|
|
29
|
+
tools.push(tool);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getRegisteredTools(): readonly RegisteredTool[] {
|
|
33
|
+
return tools;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Wire every registered tool onto the MCP server. Called by the composition root. */
|
|
37
|
+
export function applyTools(server: McpServerLike): void {
|
|
38
|
+
for (const tool of tools) {
|
|
39
|
+
server.registerTool(
|
|
40
|
+
tool.name,
|
|
41
|
+
{ description: tool.description, inputSchema: tool.inputSchema },
|
|
42
|
+
(input) => tool.handler(input),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
/**
|
|
3
|
+
* Example MCP resource (read-only) — exposes data a client can fetch by URI.
|
|
4
|
+
* Resources mirror the tool pattern: validate, call a *read* use-case, return
|
|
5
|
+
* its content. A worked stub: wire it onto the server from your composition root
|
|
6
|
+
* and replace the body with a real read use-case.
|
|
7
|
+
*/
|
|
8
|
+
import type { McpServerLike } from "../sdk.js";
|
|
9
|
+
|
|
10
|
+
type ResourceCapableServer = McpServerLike & {
|
|
11
|
+
registerResource?: (
|
|
12
|
+
name: string,
|
|
13
|
+
uri: string,
|
|
14
|
+
handler: () => Promise<{ contents: Array<{ uri: string; text: string }> }>,
|
|
15
|
+
) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function registerExampleResource(server: McpServerLike): void {
|
|
19
|
+
(server as ResourceCapableServer).registerResource?.(
|
|
20
|
+
"example",
|
|
21
|
+
"example://info",
|
|
22
|
+
async () => ({
|
|
23
|
+
contents: [
|
|
24
|
+
{ uri: "example://info", text: "Replace with a read use-case." },
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @hexagen-server-only — loads the MCP SDK; must never reach a client bundle (ADR-0037).
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic-import wrapper for `@modelcontextprotocol/sdk` (ADR-0010).
|
|
4
|
+
*
|
|
5
|
+
* The SDK ships `node:`-scheme imports that break webpack when imported
|
|
6
|
+
* statically into a client-bundled app, so it is loaded at runtime via
|
|
7
|
+
* `import()` instead. A side benefit: a missing SDK fails *here*, with a clear
|
|
8
|
+
* install hint, rather than breaking the build.
|
|
9
|
+
*
|
|
10
|
+
* Install it: `npm install @modelcontextprotocol/sdk zod`
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// The SDK is loaded at runtime, so its types aren't statically available here;
|
|
14
|
+
// the composition root treats the returned values structurally.
|
|
15
|
+
export interface LoadedSdk {
|
|
16
|
+
McpServer: new (info: { name: string; version: string }) => McpServerLike;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface McpServerLike {
|
|
20
|
+
registerTool(
|
|
21
|
+
name: string,
|
|
22
|
+
config: { description: string; inputSchema: Record<string, unknown> },
|
|
23
|
+
handler: (input: Record<string, unknown>) => Promise<unknown>,
|
|
24
|
+
): void;
|
|
25
|
+
connect(transport: unknown): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let cached: Promise<LoadedSdk> | null = null;
|
|
29
|
+
|
|
30
|
+
export function loadSdk(): Promise<LoadedSdk> {
|
|
31
|
+
cached ??= import("@modelcontextprotocol/sdk/server/mcp.js")
|
|
32
|
+
.then((mod) => ({ McpServer: mod.McpServer as LoadedSdk["McpServer"] }))
|
|
33
|
+
.catch((cause: unknown) => {
|
|
34
|
+
cached = null;
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Failed to load @modelcontextprotocol/sdk. Install it: `npm install @modelcontextprotocol/sdk zod`.",
|
|
37
|
+
{ cause },
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
return cached;
|
|
41
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @hexagen-server-only — composition root; holds privileged use-cases (ADR-0037).
|
|
2
|
+
import { loadSdk } from "./sdk.js";
|
|
3
|
+
import { applyTools } from "./registry/tool-registry.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Builds a transport instance on demand. A **factory**, not an instance, so an
|
|
7
|
+
* addon (e.g. `mcp-server-http`) can register a fully-configured transport
|
|
8
|
+
* without this composition root knowing its options — and without depending on
|
|
9
|
+
* when it is constructed.
|
|
10
|
+
*/
|
|
11
|
+
export type TransportFactory = () => Promise<unknown>;
|
|
12
|
+
|
|
13
|
+
const transportFactories = new Map<string, TransportFactory>();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Register a transport under an `MCP_TRANSPORT` value. The base registers
|
|
17
|
+
* `stdio`; the `mcp-server-http` addon registers `streamable-http` — each from
|
|
18
|
+
* its own file via `transport/register-transports.ts`, so neither edits this file.
|
|
19
|
+
*/
|
|
20
|
+
export function registerTransport(
|
|
21
|
+
name: string,
|
|
22
|
+
factory: TransportFactory,
|
|
23
|
+
): void {
|
|
24
|
+
transportFactories.set(name, factory);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compose and start the MCP server: load the SDK (dynamic import, ADR-0010),
|
|
29
|
+
* build the server, wire the registered tools, then connect the transport
|
|
30
|
+
* selected by `MCP_TRANSPORT` (default `stdio`). `register-all.ts` and
|
|
31
|
+
* `register-transports.ts` must be imported first (see `bin/cli.ts`) so the
|
|
32
|
+
* registries are populated.
|
|
33
|
+
*/
|
|
34
|
+
export async function startServer(): Promise<void> {
|
|
35
|
+
const { McpServer } = await loadSdk();
|
|
36
|
+
const server = new McpServer({
|
|
37
|
+
name: process.env.MCP_SERVER_NAME || "{server_name}",
|
|
38
|
+
version: "0.1.0",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
applyTools(server);
|
|
42
|
+
|
|
43
|
+
const transportName = process.env.MCP_TRANSPORT || "stdio";
|
|
44
|
+
const factory = transportFactories.get(transportName);
|
|
45
|
+
if (!factory) {
|
|
46
|
+
const known = [...transportFactories.keys()].join(", ") || "(none)";
|
|
47
|
+
throw new Error(
|
|
48
|
+
`No MCP transport registered for MCP_TRANSPORT="${transportName}". Registered: ${known}.`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
await server.connect(await factory());
|
|
52
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
|
|
5
|
+
import { exampleTool } from "./example.tool.js";
|
|
6
|
+
|
|
7
|
+
describe("exampleTool", () => {
|
|
8
|
+
it("maps a successful Result to MCP text content", async () => {
|
|
9
|
+
const res = await exampleTool.handler({ name: "Ada" });
|
|
10
|
+
assert.equal(res.isError, undefined);
|
|
11
|
+
assert.match(res.content[0].text, /Ada/);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("maps a use-case failure to an MCP error (isError: true)", async () => {
|
|
15
|
+
const res = await exampleTool.handler({ name: "" });
|
|
16
|
+
assert.equal(res.isError, true);
|
|
17
|
+
assert.match(res.content[0].text, /must not be empty/);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("rejects an invalid input shape with an MCP error", async () => {
|
|
21
|
+
const res = await exampleTool.handler({ name: 123 });
|
|
22
|
+
assert.equal(res.isError, true);
|
|
23
|
+
assert.match(res.content[0].text, /Invalid input/);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("dry_run validates without performing the action", async () => {
|
|
27
|
+
const res = await exampleTool.handler({ name: "Ada", dry_run: true });
|
|
28
|
+
assert.equal(res.isError, undefined);
|
|
29
|
+
assert.match(res.content[0].text, /dry-run/);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
/**
|
|
3
|
+
* Worked example: an MCP tool is an INBOUND ADAPTER over an existing use-case —
|
|
4
|
+
* validate input, call the use-case, map its `Result` to an MCP response. No
|
|
5
|
+
* business logic lives here; the hexagon is untouched. Copy this file to add a
|
|
6
|
+
* real tool, then register it in `registry/register-all.ts`.
|
|
7
|
+
*
|
|
8
|
+
* Two patterns to keep when you copy it:
|
|
9
|
+
* 1. **Explicit `Result` -> MCP mapping, including the error path** (`isError:
|
|
10
|
+
* true`). If the error path is glossed over here, every tool copied from it
|
|
11
|
+
* will gloss over it too.
|
|
12
|
+
* 2. **`dry_run`** for any tool that mutates state (ADR-0010 #5): validate and
|
|
13
|
+
* report what *would* happen, change nothing.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import type { RegisteredTool, ToolResult } from "../registry/tool-registry.js";
|
|
17
|
+
|
|
18
|
+
// A discriminated Result — your real use-cases already return one of these.
|
|
19
|
+
// Replace `greetUseCase` with a call into your application layer.
|
|
20
|
+
type Result<T> = { ok: true; value: T } | { ok: false; error: string };
|
|
21
|
+
|
|
22
|
+
async function greetUseCase(input: {
|
|
23
|
+
name: string;
|
|
24
|
+
dryRun: boolean;
|
|
25
|
+
}): Promise<Result<string>> {
|
|
26
|
+
if (input.name.trim() === "") {
|
|
27
|
+
return { ok: false, error: "name must not be empty" };
|
|
28
|
+
}
|
|
29
|
+
if (input.dryRun) {
|
|
30
|
+
return { ok: true, value: `[dry-run] would greet ${input.name}` };
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, value: `Hello, ${input.name}, from {server_name}!` };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const InputSchema = {
|
|
36
|
+
name: z.string().describe("Who to greet"),
|
|
37
|
+
dry_run: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Validate and report the action without performing it"),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const exampleTool: RegisteredTool = {
|
|
44
|
+
name: "greet",
|
|
45
|
+
description: "Example tool — greets a name. Replace with a real use-case.",
|
|
46
|
+
inputSchema: InputSchema,
|
|
47
|
+
handler: async (raw): Promise<ToolResult> => {
|
|
48
|
+
// 1. Validate the untrusted input at the boundary.
|
|
49
|
+
const parsed = z.object(InputSchema).safeParse(raw);
|
|
50
|
+
if (!parsed.success) {
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{ type: "text", text: `Invalid input: ${parsed.error.message}` },
|
|
54
|
+
],
|
|
55
|
+
isError: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 2. Call the use-case.
|
|
60
|
+
const result = await greetUseCase({
|
|
61
|
+
name: parsed.data.name,
|
|
62
|
+
dryRun: parsed.data.dry_run ?? false,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 3. Map the Result to an MCP response — BOTH branches, explicitly.
|
|
66
|
+
if (!result.ok) {
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: `Error: ${result.error}` }],
|
|
69
|
+
isError: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { content: [{ type: "text", text: result.value }] };
|
|
73
|
+
},
|
|
74
|
+
};
|
package/dist/templates/mcp-server/files/src/infrastructure/mcp/transport/register-transports.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @hexagen-server-only
|
|
2
|
+
/**
|
|
3
|
+
* Static transport registrations. The base registers `stdio`. An addon adds a
|
|
4
|
+
* transport here with one import + one `registerTransport(...)` line — e.g. the
|
|
5
|
+
* `mcp-server-http` addon appends:
|
|
6
|
+
*
|
|
7
|
+
* import { createHttpTransport } from "./http.js";
|
|
8
|
+
* registerTransport("streamable-http", createHttpTransport);
|
|
9
|
+
*
|
|
10
|
+
* so the composition root (`server.ts`) never needs to be rewritten.
|
|
11
|
+
*/
|
|
12
|
+
import { registerTransport } from "../server.js";
|
|
13
|
+
import { createStdioTransport } from "./stdio.js";
|
|
14
|
+
|
|
15
|
+
registerTransport("stdio", createStdioTransport);
|