@vinkius-core/mcp-fusion 2.13.1 → 2.14.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/dist/cli/fusion.js +35 -35
- package/dist/cli/templates/config.js +26 -26
- package/dist/cli/templates/core.d.ts.map +1 -1
- package/dist/cli/templates/core.js +108 -111
- package/dist/cli/templates/core.js.map +1 -1
- package/dist/cli/templates/middleware.js +25 -25
- package/dist/cli/templates/readme.js +142 -142
- package/dist/cli/templates/testing.js +83 -83
- package/dist/cli/templates/tools.js +46 -46
- package/dist/cli/templates/vectors/database.js +69 -69
- package/dist/cli/templates/vectors/oauth.js +63 -63
- package/dist/cli/templates/vectors/openapi.js +97 -97
- package/dist/core/builder/FluentToolBuilder.d.ts +28 -0
- package/dist/core/builder/FluentToolBuilder.d.ts.map +1 -1
- package/dist/core/builder/FluentToolBuilder.js +38 -0
- package/dist/core/builder/FluentToolBuilder.js.map +1 -1
- package/dist/core/builder/GroupedToolBuilder.d.ts +26 -0
- package/dist/core/builder/GroupedToolBuilder.d.ts.map +1 -1
- package/dist/core/builder/GroupedToolBuilder.js +41 -0
- package/dist/core/builder/GroupedToolBuilder.js.map +1 -1
- package/dist/core/initFusion.d.ts +25 -0
- package/dist/core/initFusion.d.ts.map +1 -1
- package/dist/core/initFusion.js +5 -0
- package/dist/core/initFusion.js.map +1 -1
- package/dist/fsm/StateMachineGate.d.ts +264 -0
- package/dist/fsm/StateMachineGate.d.ts.map +1 -0
- package/dist/fsm/StateMachineGate.js +343 -0
- package/dist/fsm/StateMachineGate.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/introspection/SemanticProbe.js +49 -49
- package/dist/observability/TelemetryBus.d.ts +82 -0
- package/dist/observability/TelemetryBus.d.ts.map +1 -0
- package/dist/observability/TelemetryBus.js +335 -0
- package/dist/observability/TelemetryBus.js.map +1 -0
- package/dist/observability/TelemetryEvent.d.ts +171 -0
- package/dist/observability/TelemetryEvent.d.ts.map +1 -0
- package/dist/observability/TelemetryEvent.js +2 -0
- package/dist/observability/TelemetryEvent.js.map +1 -0
- package/dist/presenter/Presenter.d.ts +66 -0
- package/dist/presenter/Presenter.d.ts.map +1 -1
- package/dist/presenter/Presenter.js +89 -1
- package/dist/presenter/Presenter.js.map +1 -1
- package/dist/presenter/RedactEngine.d.ts +110 -0
- package/dist/presenter/RedactEngine.d.ts.map +1 -0
- package/dist/presenter/RedactEngine.js +128 -0
- package/dist/presenter/RedactEngine.js.map +1 -0
- package/dist/presenter/definePresenter.d.ts +22 -1
- package/dist/presenter/definePresenter.d.ts.map +1 -1
- package/dist/presenter/definePresenter.js +3 -0
- package/dist/presenter/definePresenter.js.map +1 -1
- package/dist/presenter/index.d.ts +2 -0
- package/dist/presenter/index.d.ts.map +1 -1
- package/dist/presenter/index.js +2 -0
- package/dist/presenter/index.js.map +1 -1
- package/dist/prompt/FluentPromptBuilder.d.ts.map +1 -1
- package/dist/server/ServerAttachment.d.ts +63 -0
- package/dist/server/ServerAttachment.d.ts.map +1 -1
- package/dist/server/ServerAttachment.js +149 -6
- package/dist/server/ServerAttachment.js.map +1 -1
- package/package.json +21 -4
package/dist/cli/fusion.js
CHANGED
|
@@ -107,41 +107,41 @@ export class ProgressTracker {
|
|
|
107
107
|
/** @internal exported for testing */
|
|
108
108
|
export const MCP_FUSION_VERSION = '1.1.0';
|
|
109
109
|
/** @internal exported for testing */
|
|
110
|
-
export const HELP = `
|
|
111
|
-
fusion — MCP Fusion CLI
|
|
112
|
-
|
|
113
|
-
USAGE
|
|
114
|
-
fusion create <name> Scaffold a new MCP Fusion server
|
|
115
|
-
fusion dev --server <entry> Start HMR dev server with auto-reload
|
|
116
|
-
fusion lock Generate or update ${LOCKFILE_NAME}
|
|
117
|
-
fusion lock --check Verify lockfile is up to date (CI gate)
|
|
118
|
-
|
|
119
|
-
CREATE OPTIONS
|
|
120
|
-
--transport <stdio|sse> Transport layer (default: stdio)
|
|
121
|
-
--vector <type> Ingestion vector: vanilla, prisma, n8n, openapi, oauth
|
|
122
|
-
--testing Include test suite (default: true)
|
|
123
|
-
--no-testing Skip test suite
|
|
124
|
-
--yes, -y Skip prompts, use defaults
|
|
125
|
-
|
|
126
|
-
DEV OPTIONS
|
|
127
|
-
--server, -s <path> Path to server entrypoint (default: auto-detect)
|
|
128
|
-
--dir, -d <path> Directory to watch for changes (default: auto-detect from server)
|
|
129
|
-
|
|
130
|
-
LOCK OPTIONS
|
|
131
|
-
--server, -s <path> Path to server entrypoint
|
|
132
|
-
--name, -n <name> Server name for lockfile header
|
|
133
|
-
--cwd <dir> Project root directory
|
|
134
|
-
|
|
135
|
-
GLOBAL
|
|
136
|
-
--help, -h Show this help message
|
|
137
|
-
|
|
138
|
-
EXAMPLES
|
|
139
|
-
fusion create my-server
|
|
140
|
-
fusion create my-server -y
|
|
141
|
-
fusion create my-server --vector prisma --transport sse
|
|
142
|
-
fusion dev --server ./src/server.ts
|
|
143
|
-
fusion dev --server ./src/server.ts --dir ./src/tools
|
|
144
|
-
fusion lock --server ./src/server.ts
|
|
110
|
+
export const HELP = `
|
|
111
|
+
fusion — MCP Fusion CLI
|
|
112
|
+
|
|
113
|
+
USAGE
|
|
114
|
+
fusion create <name> Scaffold a new MCP Fusion server
|
|
115
|
+
fusion dev --server <entry> Start HMR dev server with auto-reload
|
|
116
|
+
fusion lock Generate or update ${LOCKFILE_NAME}
|
|
117
|
+
fusion lock --check Verify lockfile is up to date (CI gate)
|
|
118
|
+
|
|
119
|
+
CREATE OPTIONS
|
|
120
|
+
--transport <stdio|sse> Transport layer (default: stdio)
|
|
121
|
+
--vector <type> Ingestion vector: vanilla, prisma, n8n, openapi, oauth
|
|
122
|
+
--testing Include test suite (default: true)
|
|
123
|
+
--no-testing Skip test suite
|
|
124
|
+
--yes, -y Skip prompts, use defaults
|
|
125
|
+
|
|
126
|
+
DEV OPTIONS
|
|
127
|
+
--server, -s <path> Path to server entrypoint (default: auto-detect)
|
|
128
|
+
--dir, -d <path> Directory to watch for changes (default: auto-detect from server)
|
|
129
|
+
|
|
130
|
+
LOCK OPTIONS
|
|
131
|
+
--server, -s <path> Path to server entrypoint
|
|
132
|
+
--name, -n <name> Server name for lockfile header
|
|
133
|
+
--cwd <dir> Project root directory
|
|
134
|
+
|
|
135
|
+
GLOBAL
|
|
136
|
+
--help, -h Show this help message
|
|
137
|
+
|
|
138
|
+
EXAMPLES
|
|
139
|
+
fusion create my-server
|
|
140
|
+
fusion create my-server -y
|
|
141
|
+
fusion create my-server --vector prisma --transport sse
|
|
142
|
+
fusion dev --server ./src/server.ts
|
|
143
|
+
fusion dev --server ./src/server.ts --dir ./src/tools
|
|
144
|
+
fusion lock --server ./src/server.ts
|
|
145
145
|
`.trim();
|
|
146
146
|
/** @internal exported for testing */
|
|
147
147
|
export function parseArgs(argv) {
|
|
@@ -85,47 +85,47 @@ export function tsconfig() {
|
|
|
85
85
|
}
|
|
86
86
|
/** Generate `.gitignore` */
|
|
87
87
|
export function gitignore() {
|
|
88
|
-
return `node_modules/
|
|
89
|
-
dist/
|
|
90
|
-
*.tsbuildinfo
|
|
91
|
-
.env
|
|
92
|
-
.env.local
|
|
93
|
-
coverage/
|
|
88
|
+
return `node_modules/
|
|
89
|
+
dist/
|
|
90
|
+
*.tsbuildinfo
|
|
91
|
+
.env
|
|
92
|
+
.env.local
|
|
93
|
+
coverage/
|
|
94
94
|
`;
|
|
95
95
|
}
|
|
96
96
|
/** Generate `.env.example` with vector-specific vars */
|
|
97
97
|
export function envExample(config) {
|
|
98
|
-
let env = `# ── MCP Fusion Server Environment ─────────────────────
|
|
99
|
-
# Copy this to .env and fill in your values.
|
|
100
|
-
|
|
101
|
-
# Server
|
|
102
|
-
NODE_ENV=development
|
|
98
|
+
let env = `# ── MCP Fusion Server Environment ─────────────────────
|
|
99
|
+
# Copy this to .env and fill in your values.
|
|
100
|
+
|
|
101
|
+
# Server
|
|
102
|
+
NODE_ENV=development
|
|
103
103
|
`;
|
|
104
104
|
if (config.vector === 'prisma') {
|
|
105
|
-
env += `
|
|
106
|
-
# Database (Prisma)
|
|
107
|
-
DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"
|
|
105
|
+
env += `
|
|
106
|
+
# Database (Prisma)
|
|
107
|
+
DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"
|
|
108
108
|
`;
|
|
109
109
|
}
|
|
110
110
|
if (config.vector === 'n8n') {
|
|
111
|
-
env += `
|
|
112
|
-
# n8n Workflow Automation
|
|
113
|
-
N8N_BASE_URL=http://localhost:5678
|
|
114
|
-
N8N_API_KEY=your-api-key-here
|
|
111
|
+
env += `
|
|
112
|
+
# n8n Workflow Automation
|
|
113
|
+
N8N_BASE_URL=http://localhost:5678
|
|
114
|
+
N8N_API_KEY=your-api-key-here
|
|
115
115
|
`;
|
|
116
116
|
}
|
|
117
117
|
if (config.vector === 'oauth') {
|
|
118
|
-
env += `
|
|
119
|
-
# OAuth Device Flow (RFC 8628)
|
|
120
|
-
OAUTH_CLIENT_ID=your-client-id
|
|
121
|
-
OAUTH_AUTH_ENDPOINT=https://api.example.com/oauth/device/code
|
|
122
|
-
OAUTH_TOKEN_ENDPOINT=https://api.example.com/oauth/device/token
|
|
118
|
+
env += `
|
|
119
|
+
# OAuth Device Flow (RFC 8628)
|
|
120
|
+
OAUTH_CLIENT_ID=your-client-id
|
|
121
|
+
OAUTH_AUTH_ENDPOINT=https://api.example.com/oauth/device/code
|
|
122
|
+
OAUTH_TOKEN_ENDPOINT=https://api.example.com/oauth/device/token
|
|
123
123
|
`;
|
|
124
124
|
}
|
|
125
125
|
if (config.transport === 'sse') {
|
|
126
|
-
env += `
|
|
127
|
-
# SSE Transport
|
|
128
|
-
PORT=3001
|
|
126
|
+
env += `
|
|
127
|
+
# SSE Transport
|
|
128
|
+
PORT=3001
|
|
129
129
|
`;
|
|
130
130
|
}
|
|
131
131
|
return env;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,6DAA6D;AAC7D,wBAAgB,QAAQ,IAAI,MAAM,CAajC;AAED,qEAAqE;AACrE,wBAAgB,SAAS,IAAI,MAAM,CA8BlC;AAED,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,6DAA6D;AAC7D,wBAAgB,QAAQ,IAAI,MAAM,CAajC;AAED,qEAAqE;AACrE,wBAAgB,SAAS,IAAI,MAAM,CA8BlC;AAED,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CA+EtD"}
|
|
@@ -1,130 +1,127 @@
|
|
|
1
1
|
/** Generate `src/fusion.ts` — The one-file context center */
|
|
2
2
|
export function fusionTs() {
|
|
3
|
-
return `/**
|
|
4
|
-
* Fusion Instance — Context Initialization
|
|
5
|
-
*
|
|
6
|
-
* Define your context type ONCE. Every f.query(), f.mutation(),
|
|
7
|
-
* f.presenter(), f.prompt(), and f.middleware() call inherits
|
|
8
|
-
* AppContext — zero generic repetition anywhere in the codebase.
|
|
9
|
-
*/
|
|
10
|
-
import { initFusion } from '@vinkius-core/mcp-fusion';
|
|
11
|
-
import type { AppContext } from './context.js';
|
|
12
|
-
|
|
13
|
-
export const f = initFusion<AppContext>();
|
|
3
|
+
return `/**
|
|
4
|
+
* Fusion Instance — Context Initialization
|
|
5
|
+
*
|
|
6
|
+
* Define your context type ONCE. Every f.query(), f.mutation(),
|
|
7
|
+
* f.presenter(), f.prompt(), and f.middleware() call inherits
|
|
8
|
+
* AppContext — zero generic repetition anywhere in the codebase.
|
|
9
|
+
*/
|
|
10
|
+
import { initFusion } from '@vinkius-core/mcp-fusion';
|
|
11
|
+
import type { AppContext } from './context.js';
|
|
12
|
+
|
|
13
|
+
export const f = initFusion<AppContext>();
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
/** Generate `src/context.ts` — Application context type + factory */
|
|
17
17
|
export function contextTs() {
|
|
18
|
-
return `/**
|
|
19
|
-
* Application Context — Shared State for Every Tool Handler
|
|
20
|
-
*
|
|
21
|
-
* Every f.query() / f.mutation() handler receives (input, ctx)
|
|
22
|
-
* where ctx is this AppContext. Extend it with your own services
|
|
23
|
-
* (DB client, auth, external APIs, etc.)
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export interface AppContext {
|
|
27
|
-
/** Current user role for RBAC checks */
|
|
28
|
-
role: 'ADMIN' | 'USER' | 'GUEST';
|
|
29
|
-
|
|
30
|
-
/** Tenant identifier (multi-tenancy) */
|
|
31
|
-
tenantId: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create the application context for each tool invocation.
|
|
36
|
-
*
|
|
37
|
-
* In production, hydrate this from the MCP session metadata,
|
|
38
|
-
* JWT tokens, or environment variables.
|
|
39
|
-
*/
|
|
40
|
-
export function createContext(): AppContext {
|
|
41
|
-
return {
|
|
42
|
-
role: 'ADMIN',
|
|
43
|
-
tenantId: 'default',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
18
|
+
return `/**
|
|
19
|
+
* Application Context — Shared State for Every Tool Handler
|
|
20
|
+
*
|
|
21
|
+
* Every f.query() / f.mutation() handler receives (input, ctx)
|
|
22
|
+
* where ctx is this AppContext. Extend it with your own services
|
|
23
|
+
* (DB client, auth, external APIs, etc.)
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export interface AppContext {
|
|
27
|
+
/** Current user role for RBAC checks */
|
|
28
|
+
role: 'ADMIN' | 'USER' | 'GUEST';
|
|
29
|
+
|
|
30
|
+
/** Tenant identifier (multi-tenancy) */
|
|
31
|
+
tenantId: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create the application context for each tool invocation.
|
|
36
|
+
*
|
|
37
|
+
* In production, hydrate this from the MCP session metadata,
|
|
38
|
+
* JWT tokens, or environment variables.
|
|
39
|
+
*/
|
|
40
|
+
export function createContext(): AppContext {
|
|
41
|
+
return {
|
|
42
|
+
role: 'ADMIN',
|
|
43
|
+
tenantId: 'default',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
46
|
`;
|
|
47
47
|
}
|
|
48
48
|
/** Generate `src/server.ts` — Bootstrap with autoDiscover + transport */
|
|
49
49
|
export function serverTs(config) {
|
|
50
50
|
const transportImport = config.transport === 'stdio'
|
|
51
51
|
? `import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';`
|
|
52
|
-
: `import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
52
|
+
: `import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
53
53
|
import { createServer } from 'node:http';`;
|
|
54
54
|
const transportSetup = config.transport === 'stdio'
|
|
55
|
-
? `
|
|
56
|
-
// ── Transport ────────────────────────────────────────────
|
|
57
|
-
const transport = new StdioServerTransport();
|
|
58
|
-
await server.connect(transport);
|
|
55
|
+
? `
|
|
56
|
+
// ── Transport ────────────────────────────────────────────
|
|
57
|
+
const transport = new StdioServerTransport();
|
|
58
|
+
await server.connect(transport);
|
|
59
59
|
console.error('⚡ MCP Fusion server running on stdio');`
|
|
60
|
-
: `
|
|
61
|
-
// ── Transport ────────────────────────────────────────────
|
|
62
|
-
const PORT = Number(process.env['PORT'] ?? 3001);
|
|
63
|
-
const transports = new Map<string, SSEServerTransport>();
|
|
64
|
-
|
|
65
|
-
const httpServer = createServer(async (req, res) => {
|
|
66
|
-
if (req.method === 'GET' && req.url === '/sse') {
|
|
67
|
-
const sseTransport = new SSEServerTransport('/mcp/messages', res);
|
|
68
|
-
transports.set(sseTransport.sessionId, sseTransport);
|
|
69
|
-
res.on('close', () => transports.delete(sseTransport.sessionId));
|
|
70
|
-
await server.connect(sseTransport);
|
|
71
|
-
} else if (req.method === 'POST' && req.url?.startsWith('/mcp/messages')) {
|
|
72
|
-
const url = new URL(req.url, \`http://localhost:\${PORT}\`);
|
|
73
|
-
const sessionId = url.searchParams.get('sessionId') ?? '';
|
|
74
|
-
const transport = transports.get(sessionId);
|
|
75
|
-
if (transport) {
|
|
76
|
-
await transport.handlePostMessage(req, res);
|
|
77
|
-
} else {
|
|
78
|
-
res.writeHead(400).end('Unknown session');
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
res.writeHead(404).end();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
httpServer.listen(PORT, () => {
|
|
86
|
-
console.error(\`⚡ MCP Fusion SSE server on http://localhost:\${PORT}/sse\`);
|
|
60
|
+
: `
|
|
61
|
+
// ── Transport ────────────────────────────────────────────
|
|
62
|
+
const PORT = Number(process.env['PORT'] ?? 3001);
|
|
63
|
+
const transports = new Map<string, SSEServerTransport>();
|
|
64
|
+
|
|
65
|
+
const httpServer = createServer(async (req, res) => {
|
|
66
|
+
if (req.method === 'GET' && req.url === '/sse') {
|
|
67
|
+
const sseTransport = new SSEServerTransport('/mcp/messages', res);
|
|
68
|
+
transports.set(sseTransport.sessionId, sseTransport);
|
|
69
|
+
res.on('close', () => transports.delete(sseTransport.sessionId));
|
|
70
|
+
await server.connect(sseTransport);
|
|
71
|
+
} else if (req.method === 'POST' && req.url?.startsWith('/mcp/messages')) {
|
|
72
|
+
const url = new URL(req.url, \`http://localhost:\${PORT}\`);
|
|
73
|
+
const sessionId = url.searchParams.get('sessionId') ?? '';
|
|
74
|
+
const transport = transports.get(sessionId);
|
|
75
|
+
if (transport) {
|
|
76
|
+
await transport.handlePostMessage(req, res);
|
|
77
|
+
} else {
|
|
78
|
+
res.writeHead(400).end('Unknown session');
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
res.writeHead(404).end();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
httpServer.listen(PORT, () => {
|
|
86
|
+
console.error(\`⚡ MCP Fusion SSE server on http://localhost:\${PORT}/sse\`);
|
|
87
87
|
});`;
|
|
88
|
-
return `/**
|
|
89
|
-
* Server Bootstrap — MCP Fusion with autoDiscover
|
|
90
|
-
*
|
|
91
|
-
* Tools are auto-discovered from src/tools/ — drop a file,
|
|
92
|
-
* it becomes a tool. No manual imports or registration needed.
|
|
93
|
-
*/
|
|
94
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
95
|
-
${transportImport}
|
|
96
|
-
import { ToolRegistry, autoDiscover, PromptRegistry } from '@vinkius-core/mcp-fusion';
|
|
97
|
-
import type { AppContext } from './context.js';
|
|
98
|
-
import { createContext } from './context.js';
|
|
99
|
-
import { f } from './fusion.js';
|
|
100
|
-
import { GreetPrompt } from './prompts/greet.js';
|
|
101
|
-
|
|
102
|
-
// ── Registries ───────────────────────────────────────────
|
|
103
|
-
const registry = f.registry();
|
|
104
|
-
const prompts = new PromptRegistry<AppContext>();
|
|
105
|
-
|
|
106
|
-
// ── Auto-Discover Tools ──────────────────────────────────
|
|
107
|
-
const discovered = await autoDiscover(registry, new URL('./tools', import.meta.url).pathname);
|
|
108
|
-
console.error(\`📦 Discovered \${discovered.length} tool file(s)\`);
|
|
109
|
-
|
|
110
|
-
// ── Register Prompts ─────────────────────────────────────
|
|
111
|
-
prompts.register(GreetPrompt);
|
|
112
|
-
console.error(\`💬 Registered \${prompts.size} prompt(s)\`);
|
|
113
|
-
|
|
114
|
-
// ── Server ───────────────────────────────────────────────
|
|
115
|
-
const server = new Server(
|
|
116
|
-
{ name: '${config.name}', version: '0.1.0' },
|
|
117
|
-
{ capabilities: { tools: {}, prompts: {} } },
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
registry.attachToServer(server, {
|
|
121
|
-
contextFactory: () => createContext(),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
contextFactory: () => createContext(),
|
|
126
|
-
});
|
|
127
|
-
${transportSetup}
|
|
88
|
+
return `/**
|
|
89
|
+
* Server Bootstrap — MCP Fusion with autoDiscover
|
|
90
|
+
*
|
|
91
|
+
* Tools are auto-discovered from src/tools/ — drop a file,
|
|
92
|
+
* it becomes a tool. No manual imports or registration needed.
|
|
93
|
+
*/
|
|
94
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
95
|
+
${transportImport}
|
|
96
|
+
import { ToolRegistry, autoDiscover, PromptRegistry } from '@vinkius-core/mcp-fusion';
|
|
97
|
+
import type { AppContext } from './context.js';
|
|
98
|
+
import { createContext } from './context.js';
|
|
99
|
+
import { f } from './fusion.js';
|
|
100
|
+
import { GreetPrompt } from './prompts/greet.js';
|
|
101
|
+
|
|
102
|
+
// ── Registries ───────────────────────────────────────────
|
|
103
|
+
const registry = f.registry();
|
|
104
|
+
const prompts = new PromptRegistry<AppContext>();
|
|
105
|
+
|
|
106
|
+
// ── Auto-Discover Tools ──────────────────────────────────
|
|
107
|
+
const discovered = await autoDiscover(registry, new URL('./tools', import.meta.url).pathname);
|
|
108
|
+
console.error(\`📦 Discovered \${discovered.length} tool file(s)\`);
|
|
109
|
+
|
|
110
|
+
// ── Register Prompts ─────────────────────────────────────
|
|
111
|
+
prompts.register(GreetPrompt);
|
|
112
|
+
console.error(\`💬 Registered \${prompts.size} prompt(s)\`);
|
|
113
|
+
|
|
114
|
+
// ── Server ───────────────────────────────────────────────
|
|
115
|
+
const server = new Server(
|
|
116
|
+
{ name: '${config.name}', version: '0.1.0' },
|
|
117
|
+
{ capabilities: { tools: {}, prompts: {} } },
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
registry.attachToServer(server, {
|
|
121
|
+
contextFactory: () => createContext(),
|
|
122
|
+
prompts,
|
|
123
|
+
});
|
|
124
|
+
${transportSetup}
|
|
128
125
|
`;
|
|
129
126
|
}
|
|
130
127
|
//# sourceMappingURL=core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/cli/templates/core.ts"],"names":[],"mappings":"AAQA,6DAA6D;AAC7D,MAAM,UAAU,QAAQ;IACpB,OAAO;;;;;;;;;;;CAWV,CAAC;AACF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,SAAS;IACrB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BV,CAAC;AACF,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,QAAQ,CAAC,MAAqB;IAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,KAAK,OAAO;QAChD,CAAC,CAAC,mFAAmF;QACrF,CAAC,CAAC;0CACgC,CAAC;IAEvC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,KAAK,OAAO;QAC/C,CAAC,CAAC;;;;uDAI6C;QAC/C,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BN,CAAC;IAED,OAAO;;;;;;;EAOT,eAAe;;;;;;;;;;;;;;;;;;;;;eAqBF,MAAM,CAAC,IAAI
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/cli/templates/core.ts"],"names":[],"mappings":"AAQA,6DAA6D;AAC7D,MAAM,UAAU,QAAQ;IACpB,OAAO;;;;;;;;;;;CAWV,CAAC;AACF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,SAAS;IACrB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BV,CAAC;AACF,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,QAAQ,CAAC,MAAqB;IAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,KAAK,OAAO;QAChD,CAAC,CAAC,mFAAmF;QACrF,CAAC,CAAC;0CACgC,CAAC;IAEvC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,KAAK,OAAO;QAC/C,CAAC,CAAC;;;;uDAI6C;QAC/C,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BN,CAAC;IAED,OAAO;;;;;;;EAOT,eAAe;;;;;;;;;;;;;;;;;;;;;eAqBF,MAAM,CAAC,IAAI;;;;;;;;EAQxB,cAAc;CACf,CAAC;AACF,CAAC"}
|
|
@@ -4,31 +4,31 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Generate `src/middleware/auth.ts` — RBAC middleware */
|
|
6
6
|
export function authMiddlewareTs() {
|
|
7
|
-
return `/**
|
|
8
|
-
* Auth Middleware — RBAC Guard (Fluent API)
|
|
9
|
-
*
|
|
10
|
-
* Demonstrates f.middleware() — tRPC-style context derivation.
|
|
11
|
-
* Rejects GUEST requests with a structured error.
|
|
12
|
-
*
|
|
13
|
-
* Usage in tools:
|
|
14
|
-
* f.query('users.list')
|
|
15
|
-
* .use(withAuth)
|
|
16
|
-
* .handle(async (input, ctx) => {
|
|
17
|
-
* // ctx now has ctx.role guaranteed non-GUEST
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* In production, replace with JWT validation,
|
|
21
|
-
* API key checks, or OAuth token verification.
|
|
22
|
-
*/
|
|
23
|
-
import { f } from '../fusion.js';
|
|
24
|
-
import { error } from '@vinkius-core/mcp-fusion';
|
|
25
|
-
|
|
26
|
-
export const withAuth = f.middleware(async (ctx) => {
|
|
27
|
-
if (ctx.role === 'GUEST') {
|
|
28
|
-
throw error('Access denied. Authentication required.');
|
|
29
|
-
}
|
|
30
|
-
return { verified: true as const };
|
|
31
|
-
});
|
|
7
|
+
return `/**
|
|
8
|
+
* Auth Middleware — RBAC Guard (Fluent API)
|
|
9
|
+
*
|
|
10
|
+
* Demonstrates f.middleware() — tRPC-style context derivation.
|
|
11
|
+
* Rejects GUEST requests with a structured error.
|
|
12
|
+
*
|
|
13
|
+
* Usage in tools:
|
|
14
|
+
* f.query('users.list')
|
|
15
|
+
* .use(withAuth)
|
|
16
|
+
* .handle(async (input, ctx) => {
|
|
17
|
+
* // ctx now has ctx.role guaranteed non-GUEST
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* In production, replace with JWT validation,
|
|
21
|
+
* API key checks, or OAuth token verification.
|
|
22
|
+
*/
|
|
23
|
+
import { f } from '../fusion.js';
|
|
24
|
+
import { error } from '@vinkius-core/mcp-fusion';
|
|
25
|
+
|
|
26
|
+
export const withAuth = f.middleware(async (ctx) => {
|
|
27
|
+
if (ctx.role === 'GUEST') {
|
|
28
|
+
throw error('Access denied. Authentication required.');
|
|
29
|
+
}
|
|
30
|
+
return { verified: true as const };
|
|
31
|
+
});
|
|
32
32
|
`;
|
|
33
33
|
}
|
|
34
34
|
//# sourceMappingURL=middleware.js.map
|