@vinkius-core/mcp-fusion 2.9.0 → 2.11.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 +31 -31
- package/dist/cli/fusion.js.map +1 -1
- package/dist/cli/templates/config.js +26 -26
- package/dist/cli/templates/core.js +111 -111
- package/dist/cli/templates/middleware.js +22 -22
- package/dist/cli/templates/readme.js +146 -146
- package/dist/cli/templates/testing.js +83 -83
- package/dist/cli/templates/tools.js +53 -53
- package/dist/cli/templates/vectors/database.js +74 -74
- package/dist/cli/templates/vectors/oauth.js +64 -64
- package/dist/cli/templates/vectors/openapi.js +97 -97
- package/dist/core/builder/GroupedToolBuilder.d.ts +41 -0
- package/dist/core/builder/GroupedToolBuilder.d.ts.map +1 -1
- package/dist/core/builder/GroupedToolBuilder.js +54 -4
- package/dist/core/builder/GroupedToolBuilder.js.map +1 -1
- package/dist/core/builder/ToolDefinitionCompiler.d.ts +1 -0
- package/dist/core/builder/ToolDefinitionCompiler.d.ts.map +1 -1
- package/dist/core/builder/ToolDefinitionCompiler.js +1 -1
- package/dist/core/builder/ToolDefinitionCompiler.js.map +1 -1
- package/dist/core/execution/ExecutionPipeline.d.ts +8 -2
- package/dist/core/execution/ExecutionPipeline.d.ts.map +1 -1
- package/dist/core/execution/ExecutionPipeline.js +18 -9
- package/dist/core/execution/ExecutionPipeline.js.map +1 -1
- package/dist/core/registry/ToolRegistry.d.ts +1 -1
- package/dist/core/registry/ToolRegistry.d.ts.map +1 -1
- package/dist/core/registry/ToolRegistry.js +1 -1
- package/dist/core/registry/ToolRegistry.js.map +1 -1
- package/dist/core/schema/SchemaGenerator.d.ts +1 -1
- package/dist/core/schema/SchemaGenerator.d.ts.map +1 -1
- package/dist/core/schema/SchemaGenerator.js +38 -1
- package/dist/core/schema/SchemaGenerator.js.map +1 -1
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/exposition/ExpositionCompiler.d.ts.map +1 -1
- package/dist/exposition/ExpositionCompiler.js +25 -2
- package/dist/exposition/ExpositionCompiler.js.map +1 -1
- package/dist/introspection/BehaviorDigest.d.ts +2 -2
- package/dist/introspection/BehaviorDigest.d.ts.map +1 -1
- package/dist/introspection/BehaviorDigest.js +38 -36
- package/dist/introspection/BehaviorDigest.js.map +1 -1
- package/dist/introspection/CapabilityLockfile.d.ts +2 -2
- package/dist/introspection/CapabilityLockfile.d.ts.map +1 -1
- package/dist/introspection/CapabilityLockfile.js +9 -9
- package/dist/introspection/CapabilityLockfile.js.map +1 -1
- package/dist/introspection/CryptoAttestation.d.ts.map +1 -1
- package/dist/introspection/CryptoAttestation.js +23 -36
- package/dist/introspection/CryptoAttestation.js.map +1 -1
- package/dist/introspection/SemanticProbe.js +49 -49
- package/dist/introspection/ToolContract.d.ts +2 -2
- package/dist/introspection/ToolContract.d.ts.map +1 -1
- package/dist/introspection/ToolContract.js +9 -9
- package/dist/introspection/ToolContract.js.map +1 -1
- package/dist/introspection/canonicalize.d.ts +16 -1
- package/dist/introspection/canonicalize.d.ts.map +1 -1
- package/dist/introspection/canonicalize.js +18 -3
- package/dist/introspection/canonicalize.js.map +1 -1
- package/dist/presenter/PostProcessor.d.ts +3 -1
- package/dist/presenter/PostProcessor.d.ts.map +1 -1
- package/dist/presenter/PostProcessor.js +4 -3
- package/dist/presenter/PostProcessor.js.map +1 -1
- package/dist/presenter/Presenter.d.ts +18 -5
- package/dist/presenter/Presenter.d.ts.map +1 -1
- package/dist/presenter/Presenter.js +39 -15
- package/dist/presenter/Presenter.js.map +1 -1
- package/dist/presenter/SelectUtils.d.ts +78 -0
- package/dist/presenter/SelectUtils.d.ts.map +1 -0
- package/dist/presenter/SelectUtils.js +141 -0
- package/dist/presenter/SelectUtils.js.map +1 -0
- package/dist/presenter/index.d.ts +1 -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/server/ServerAttachment.d.ts +1 -1
- package/dist/server/ServerAttachment.d.ts.map +1 -1
- package/dist/server/ServerAttachment.js +3 -3
- package/dist/server/ServerAttachment.js.map +1 -1
- package/package.json +118 -118
|
@@ -11,164 +11,164 @@ export function readme(config) {
|
|
|
11
11
|
const sseNote = config.transport === 'sse'
|
|
12
12
|
? `\n> **Note:** SSE transport requires the server to be running first. Run \\\`npm start\\\` before connecting.`
|
|
13
13
|
: '';
|
|
14
|
-
return `# ${config.name}
|
|
15
|
-
|
|
16
|
-
MCP Server built with [MCP Fusion](https://mcp-fusion.vinkius.com/) — the MVA framework for the Model Context Protocol.
|
|
17
|
-
|
|
18
|
-
## Quick Start
|
|
19
|
-
|
|
20
|
-
\`\`\`bash
|
|
21
|
-
npm install
|
|
22
|
-
${config.transport === 'sse' ? 'npm start' : 'npm run dev'}
|
|
23
|
-
\`\`\`
|
|
24
|
-
${config.testing ? `
|
|
25
|
-
## Testing
|
|
26
|
-
|
|
27
|
-
\`\`\`bash
|
|
28
|
-
npm test
|
|
29
|
-
\`\`\`
|
|
30
|
-
` : ''}
|
|
31
|
-
## Project Structure
|
|
32
|
-
|
|
33
|
-
\`\`\`
|
|
34
|
-
src/
|
|
35
|
-
├── fusion.ts # initFusion<AppContext>() — context center
|
|
36
|
-
├── context.ts # AppContext type + factory
|
|
37
|
-
├── server.ts # Bootstrap with autoDiscover
|
|
38
|
-
├── tools/ # Drop a file → it's a tool (autoDiscover)
|
|
39
|
-
│ └── system/
|
|
40
|
-
│ ├── health.ts # Health check with Presenter
|
|
41
|
-
│ └── echo.ts # Echo for connectivity testing
|
|
42
|
-
├── presenters/ # MVA View Layer (Egress Firewall)
|
|
43
|
-
│ └── SystemPresenter.ts
|
|
44
|
-
├── prompts/ # MCP Prompt Engine
|
|
45
|
-
│ └── greet.ts
|
|
46
|
-
└── middleware/ # RBAC guards
|
|
47
|
-
└── auth.ts
|
|
48
|
-
\`\`\`
|
|
49
|
-
|
|
50
|
-
## Client Configuration
|
|
51
|
-
|
|
52
|
-
### Cursor Editor
|
|
53
|
-
|
|
54
|
-
> **Already configured!** The \`.cursor/mcp.json\` file was generated automatically.
|
|
55
|
-
> Just open this folder in Cursor and the server connects instantly.
|
|
56
|
-
${sseNote}
|
|
57
|
-
|
|
58
|
-
### Claude Desktop
|
|
59
|
-
|
|
60
|
-
Add to your \`claude_desktop_config.json\`:
|
|
61
|
-
|
|
62
|
-
\`\`\`json
|
|
63
|
-
${clientConfig}
|
|
64
|
-
\`\`\`
|
|
65
|
-
${vectorReadmeSection(config)}
|
|
66
|
-
## Adding New Tools
|
|
67
|
-
|
|
68
|
-
Create a new file in \`src/tools/\`. It's automatically discovered:
|
|
69
|
-
|
|
70
|
-
\`\`\`typescript
|
|
71
|
-
// src/tools/my-domain/my-tool.ts
|
|
72
|
-
import { f } from '../../fusion.js';
|
|
73
|
-
import { success } from '@vinkius-core/mcp-fusion';
|
|
74
|
-
|
|
75
|
-
export default f.tool({
|
|
76
|
-
name: 'my_domain.my_tool',
|
|
77
|
-
description: 'What this tool does',
|
|
78
|
-
input: {
|
|
79
|
-
query: { type: 'string', description: 'Search query' },
|
|
80
|
-
},
|
|
81
|
-
handler: async ({ input, ctx }) => {
|
|
82
|
-
return success({ result: input.query });
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
\`\`\`
|
|
86
|
-
|
|
87
|
-
No registration needed. The \`autoDiscover()\` system picks it up automatically.
|
|
88
|
-
|
|
89
|
-
## Documentation
|
|
90
|
-
|
|
91
|
-
- [MCP Fusion Docs](https://mcp-fusion.vinkius.com/)
|
|
92
|
-
- [Presenter — Egress Firewall](https://mcp-fusion.vinkius.com/presenter)
|
|
93
|
-
- [DX Guide — initFusion()](https://mcp-fusion.vinkius.com/dx-guide)
|
|
94
|
-
- [Testing](https://mcp-fusion.vinkius.com/testing)
|
|
14
|
+
return `# ${config.name}
|
|
15
|
+
|
|
16
|
+
MCP Server built with [MCP Fusion](https://mcp-fusion.vinkius.com/) — the MVA framework for the Model Context Protocol.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
\`\`\`bash
|
|
21
|
+
npm install
|
|
22
|
+
${config.transport === 'sse' ? 'npm start' : 'npm run dev'}
|
|
23
|
+
\`\`\`
|
|
24
|
+
${config.testing ? `
|
|
25
|
+
## Testing
|
|
26
|
+
|
|
27
|
+
\`\`\`bash
|
|
28
|
+
npm test
|
|
29
|
+
\`\`\`
|
|
30
|
+
` : ''}
|
|
31
|
+
## Project Structure
|
|
32
|
+
|
|
33
|
+
\`\`\`
|
|
34
|
+
src/
|
|
35
|
+
├── fusion.ts # initFusion<AppContext>() — context center
|
|
36
|
+
├── context.ts # AppContext type + factory
|
|
37
|
+
├── server.ts # Bootstrap with autoDiscover
|
|
38
|
+
├── tools/ # Drop a file → it's a tool (autoDiscover)
|
|
39
|
+
│ └── system/
|
|
40
|
+
│ ├── health.ts # Health check with Presenter
|
|
41
|
+
│ └── echo.ts # Echo for connectivity testing
|
|
42
|
+
├── presenters/ # MVA View Layer (Egress Firewall)
|
|
43
|
+
│ └── SystemPresenter.ts
|
|
44
|
+
├── prompts/ # MCP Prompt Engine
|
|
45
|
+
│ └── greet.ts
|
|
46
|
+
└── middleware/ # RBAC guards
|
|
47
|
+
└── auth.ts
|
|
48
|
+
\`\`\`
|
|
49
|
+
|
|
50
|
+
## Client Configuration
|
|
51
|
+
|
|
52
|
+
### Cursor Editor
|
|
53
|
+
|
|
54
|
+
> **Already configured!** The \`.cursor/mcp.json\` file was generated automatically.
|
|
55
|
+
> Just open this folder in Cursor and the server connects instantly.
|
|
56
|
+
${sseNote}
|
|
57
|
+
|
|
58
|
+
### Claude Desktop
|
|
59
|
+
|
|
60
|
+
Add to your \`claude_desktop_config.json\`:
|
|
61
|
+
|
|
62
|
+
\`\`\`json
|
|
63
|
+
${clientConfig}
|
|
64
|
+
\`\`\`
|
|
65
|
+
${vectorReadmeSection(config)}
|
|
66
|
+
## Adding New Tools
|
|
67
|
+
|
|
68
|
+
Create a new file in \`src/tools/\`. It's automatically discovered:
|
|
69
|
+
|
|
70
|
+
\`\`\`typescript
|
|
71
|
+
// src/tools/my-domain/my-tool.ts
|
|
72
|
+
import { f } from '../../fusion.js';
|
|
73
|
+
import { success } from '@vinkius-core/mcp-fusion';
|
|
74
|
+
|
|
75
|
+
export default f.tool({
|
|
76
|
+
name: 'my_domain.my_tool',
|
|
77
|
+
description: 'What this tool does',
|
|
78
|
+
input: {
|
|
79
|
+
query: { type: 'string', description: 'Search query' },
|
|
80
|
+
},
|
|
81
|
+
handler: async ({ input, ctx }) => {
|
|
82
|
+
return success({ result: input.query });
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
No registration needed. The \`autoDiscover()\` system picks it up automatically.
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
- [MCP Fusion Docs](https://mcp-fusion.vinkius.com/)
|
|
92
|
+
- [Presenter — Egress Firewall](https://mcp-fusion.vinkius.com/presenter)
|
|
93
|
+
- [DX Guide — initFusion()](https://mcp-fusion.vinkius.com/dx-guide)
|
|
94
|
+
- [Testing](https://mcp-fusion.vinkius.com/testing)
|
|
95
95
|
`;
|
|
96
96
|
}
|
|
97
97
|
/** Vector-specific README section */
|
|
98
98
|
function vectorReadmeSection(config) {
|
|
99
99
|
switch (config.vector) {
|
|
100
100
|
case 'prisma':
|
|
101
|
-
return `
|
|
102
|
-
## Database Setup (Prisma)
|
|
103
|
-
|
|
104
|
-
1. Configure your database URL in \`.env\`:
|
|
105
|
-
\`\`\`
|
|
106
|
-
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
|
|
107
|
-
\`\`\`
|
|
108
|
-
|
|
109
|
-
2. Edit \`prisma/schema.prisma\` to define your models
|
|
110
|
-
|
|
111
|
-
3. Generate the Prisma client and Fusion tools:
|
|
112
|
-
\`\`\`bash
|
|
113
|
-
npm run db:generate
|
|
114
|
-
\`\`\`
|
|
115
|
-
|
|
116
|
-
4. Push the schema to your database:
|
|
117
|
-
\`\`\`bash
|
|
118
|
-
npm run db:push
|
|
119
|
-
\`\`\`
|
|
120
|
-
|
|
121
|
-
Use \`/// @fusion.hide\` on sensitive fields to strip them from the Egress Firewall.
|
|
101
|
+
return `
|
|
102
|
+
## Database Setup (Prisma)
|
|
103
|
+
|
|
104
|
+
1. Configure your database URL in \`.env\`:
|
|
105
|
+
\`\`\`
|
|
106
|
+
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
|
|
107
|
+
\`\`\`
|
|
108
|
+
|
|
109
|
+
2. Edit \`prisma/schema.prisma\` to define your models
|
|
110
|
+
|
|
111
|
+
3. Generate the Prisma client and Fusion tools:
|
|
112
|
+
\`\`\`bash
|
|
113
|
+
npm run db:generate
|
|
114
|
+
\`\`\`
|
|
115
|
+
|
|
116
|
+
4. Push the schema to your database:
|
|
117
|
+
\`\`\`bash
|
|
118
|
+
npm run db:push
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
Use \`/// @fusion.hide\` on sensitive fields to strip them from the Egress Firewall.
|
|
122
122
|
`;
|
|
123
123
|
case 'n8n':
|
|
124
|
-
return `
|
|
125
|
-
## n8n Workflow Setup
|
|
126
|
-
|
|
127
|
-
1. Configure your n8n instance in \`.env\`:
|
|
128
|
-
\`\`\`
|
|
129
|
-
N8N_BASE_URL=http://localhost:5678
|
|
130
|
-
N8N_API_KEY=your-api-key
|
|
131
|
-
\`\`\`
|
|
132
|
-
|
|
133
|
-
2. The connector in \`src/n8n.ts\` auto-discovers webhook workflows
|
|
134
|
-
and registers them as MCP tools.
|
|
124
|
+
return `
|
|
125
|
+
## n8n Workflow Setup
|
|
126
|
+
|
|
127
|
+
1. Configure your n8n instance in \`.env\`:
|
|
128
|
+
\`\`\`
|
|
129
|
+
N8N_BASE_URL=http://localhost:5678
|
|
130
|
+
N8N_API_KEY=your-api-key
|
|
131
|
+
\`\`\`
|
|
132
|
+
|
|
133
|
+
2. The connector in \`src/n8n.ts\` auto-discovers webhook workflows
|
|
134
|
+
and registers them as MCP tools.
|
|
135
135
|
`;
|
|
136
136
|
case 'openapi':
|
|
137
|
-
return `
|
|
138
|
-
## OpenAPI Generator Setup
|
|
139
|
-
|
|
140
|
-
1. Replace \`openapi.yaml\` with your actual OpenAPI 3.x spec
|
|
141
|
-
|
|
142
|
-
2. Generate the MCP server from the spec:
|
|
143
|
-
\`\`\`bash
|
|
144
|
-
npx mcp-fusion-openapi-gen ./openapi.yaml --outDir ./src/generated
|
|
145
|
-
\`\`\`
|
|
146
|
-
|
|
147
|
-
3. Import and register the generated tools in \`src/server.ts\`
|
|
137
|
+
return `
|
|
138
|
+
## OpenAPI Generator Setup
|
|
139
|
+
|
|
140
|
+
1. Replace \`openapi.yaml\` with your actual OpenAPI 3.x spec
|
|
141
|
+
|
|
142
|
+
2. Generate the MCP server from the spec:
|
|
143
|
+
\`\`\`bash
|
|
144
|
+
npx mcp-fusion-openapi-gen ./openapi.yaml --outDir ./src/generated
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
3. Import and register the generated tools in \`src/server.ts\`
|
|
148
148
|
`;
|
|
149
149
|
case 'oauth':
|
|
150
|
-
return `
|
|
151
|
-
## OAuth Device Flow Setup
|
|
152
|
-
|
|
153
|
-
1. Configure your OAuth provider in \`.env\`:
|
|
154
|
-
\`\`\`
|
|
155
|
-
OAUTH_CLIENT_ID=your-client-id
|
|
156
|
-
OAUTH_AUTH_ENDPOINT=https://api.example.com/oauth/device/code
|
|
157
|
-
OAUTH_TOKEN_ENDPOINT=https://api.example.com/oauth/device/token
|
|
158
|
-
\`\`\`
|
|
159
|
-
|
|
160
|
-
2. The auth tool in \`src/auth.ts\` is pre-configured with login, complete, status, and logout actions.
|
|
161
|
-
|
|
162
|
-
3. Protect any tool with the \`withAuth\` middleware from \`src/middleware/auth.ts\`:
|
|
163
|
-
\`\`\`ts
|
|
164
|
-
import { withAuth } from '../middleware/auth.js';
|
|
165
|
-
|
|
166
|
-
export default f.tool({
|
|
167
|
-
name: 'protected.action',
|
|
168
|
-
middleware: [withAuth],
|
|
169
|
-
handler: async ({ ctx }) => { /* authenticated */ },
|
|
170
|
-
});
|
|
171
|
-
\`\`\`
|
|
150
|
+
return `
|
|
151
|
+
## OAuth Device Flow Setup
|
|
152
|
+
|
|
153
|
+
1. Configure your OAuth provider in \`.env\`:
|
|
154
|
+
\`\`\`
|
|
155
|
+
OAUTH_CLIENT_ID=your-client-id
|
|
156
|
+
OAUTH_AUTH_ENDPOINT=https://api.example.com/oauth/device/code
|
|
157
|
+
OAUTH_TOKEN_ENDPOINT=https://api.example.com/oauth/device/token
|
|
158
|
+
\`\`\`
|
|
159
|
+
|
|
160
|
+
2. The auth tool in \`src/auth.ts\` is pre-configured with login, complete, status, and logout actions.
|
|
161
|
+
|
|
162
|
+
3. Protect any tool with the \`withAuth\` middleware from \`src/middleware/auth.ts\`:
|
|
163
|
+
\`\`\`ts
|
|
164
|
+
import { withAuth } from '../middleware/auth.js';
|
|
165
|
+
|
|
166
|
+
export default f.tool({
|
|
167
|
+
name: 'protected.action',
|
|
168
|
+
middleware: [withAuth],
|
|
169
|
+
handler: async ({ ctx }) => { /* authenticated */ },
|
|
170
|
+
});
|
|
171
|
+
\`\`\`
|
|
172
172
|
`;
|
|
173
173
|
default:
|
|
174
174
|
return '';
|
|
@@ -4,97 +4,97 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Generate `vitest.config.ts` */
|
|
6
6
|
export function vitestConfig() {
|
|
7
|
-
return `import { defineConfig } from 'vitest/config';
|
|
8
|
-
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
test: {
|
|
11
|
-
include: ['tests/**/*.test.ts'],
|
|
12
|
-
},
|
|
13
|
-
});
|
|
7
|
+
return `import { defineConfig } from 'vitest/config';
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
test: {
|
|
11
|
+
include: ['tests/**/*.test.ts'],
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
/** Generate `tests/setup.ts` — Test infrastructure */
|
|
17
17
|
export function testSetupTs() {
|
|
18
|
-
return `/**
|
|
19
|
-
* Test Setup — In-Memory MVA Emulator
|
|
20
|
-
*
|
|
21
|
-
* Creates a FusionTester that runs the full pipeline
|
|
22
|
-
* (Zod → Middleware → Handler → Egress Firewall)
|
|
23
|
-
* without any network transport.
|
|
24
|
-
*
|
|
25
|
-
* 2ms per test. $0.00 in tokens. Zero servers.
|
|
26
|
-
*/
|
|
27
|
-
import { createFusionTester } from '@vinkius-core/mcp-fusion-testing';
|
|
28
|
-
import { ToolRegistry, autoDiscover } from '@vinkius-core/mcp-fusion';
|
|
29
|
-
import type { AppContext } from '../src/context.js';
|
|
30
|
-
|
|
31
|
-
const registry = new ToolRegistry<AppContext>();
|
|
32
|
-
await autoDiscover(registry, new URL('../src/tools', import.meta.url).pathname);
|
|
33
|
-
|
|
34
|
-
export const tester = createFusionTester(registry, {
|
|
35
|
-
contextFactory: () => ({
|
|
36
|
-
role: 'ADMIN' as const,
|
|
37
|
-
tenantId: 'test-tenant',
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
18
|
+
return `/**
|
|
19
|
+
* Test Setup — In-Memory MVA Emulator
|
|
20
|
+
*
|
|
21
|
+
* Creates a FusionTester that runs the full pipeline
|
|
22
|
+
* (Zod → Middleware → Handler → Egress Firewall)
|
|
23
|
+
* without any network transport.
|
|
24
|
+
*
|
|
25
|
+
* 2ms per test. $0.00 in tokens. Zero servers.
|
|
26
|
+
*/
|
|
27
|
+
import { createFusionTester } from '@vinkius-core/mcp-fusion-testing';
|
|
28
|
+
import { ToolRegistry, autoDiscover } from '@vinkius-core/mcp-fusion';
|
|
29
|
+
import type { AppContext } from '../src/context.js';
|
|
30
|
+
|
|
31
|
+
const registry = new ToolRegistry<AppContext>();
|
|
32
|
+
await autoDiscover(registry, new URL('../src/tools', import.meta.url).pathname);
|
|
33
|
+
|
|
34
|
+
export const tester = createFusionTester(registry, {
|
|
35
|
+
contextFactory: () => ({
|
|
36
|
+
role: 'ADMIN' as const,
|
|
37
|
+
tenantId: 'test-tenant',
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
40
|
`;
|
|
41
41
|
}
|
|
42
42
|
/** Generate `tests/system.test.ts` — Egress Firewall + RBAC tests */
|
|
43
43
|
export function systemTestTs() {
|
|
44
|
-
return `/**
|
|
45
|
-
* System Tools — Egress Firewall & RBAC Tests
|
|
46
|
-
*
|
|
47
|
-
* Proves that:
|
|
48
|
-
* 1. The Presenter strips undeclared fields (SOC2 CC6.1)
|
|
49
|
-
* 2. RBAC middleware blocks GUEST access (SOC2 CC6.3)
|
|
50
|
-
* 3. System rules from .describe() are injected
|
|
51
|
-
*/
|
|
52
|
-
import { describe, it, expect } from 'vitest';
|
|
53
|
-
import { tester } from './setup.js';
|
|
54
|
-
|
|
55
|
-
describe('System Tools', () => {
|
|
56
|
-
describe('Egress Firewall', () => {
|
|
57
|
-
it('should return validated health data through the Presenter', async () => {
|
|
58
|
-
const result = await tester.callAction('system', 'health');
|
|
59
|
-
|
|
60
|
-
expect(result.isError).toBe(false);
|
|
61
|
-
expect(result.data).toHaveProperty('status');
|
|
62
|
-
expect(result.data).toHaveProperty('uptime');
|
|
63
|
-
expect(result.data).toHaveProperty('version');
|
|
64
|
-
expect(result.data).toHaveProperty('timestamp');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should strip undeclared fields (tenant must NOT leak)', async () => {
|
|
68
|
-
const result = await tester.callAction('system', 'health');
|
|
69
|
-
|
|
70
|
-
expect(result.isError).toBe(false);
|
|
71
|
-
// The handler returns 'tenant' but the Presenter schema
|
|
72
|
-
// does not declare it → stripped by Egress Firewall
|
|
73
|
-
expect(result.data).not.toHaveProperty('tenant');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should include JIT system rules from .describe()', async () => {
|
|
77
|
-
const result = await tester.callAction('system', 'health');
|
|
78
|
-
|
|
79
|
-
expect(result.systemRules.length).toBeGreaterThan(0);
|
|
80
|
-
expect(result.systemRules.some(
|
|
81
|
-
(r: string) => r.includes('uptime') || r.includes('Uptime')
|
|
82
|
-
)).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('Echo Tool', () => {
|
|
87
|
-
it('should echo the message back', async () => {
|
|
88
|
-
const result = await tester.callAction('system', 'echo', {
|
|
89
|
-
message: 'hello fusion',
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
expect(result.isError).toBe(false);
|
|
93
|
-
expect(result.data).toHaveProperty('echo', 'hello fusion');
|
|
94
|
-
expect(result.data).toHaveProperty('receivedAt');
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
44
|
+
return `/**
|
|
45
|
+
* System Tools — Egress Firewall & RBAC Tests
|
|
46
|
+
*
|
|
47
|
+
* Proves that:
|
|
48
|
+
* 1. The Presenter strips undeclared fields (SOC2 CC6.1)
|
|
49
|
+
* 2. RBAC middleware blocks GUEST access (SOC2 CC6.3)
|
|
50
|
+
* 3. System rules from .describe() are injected
|
|
51
|
+
*/
|
|
52
|
+
import { describe, it, expect } from 'vitest';
|
|
53
|
+
import { tester } from './setup.js';
|
|
54
|
+
|
|
55
|
+
describe('System Tools', () => {
|
|
56
|
+
describe('Egress Firewall', () => {
|
|
57
|
+
it('should return validated health data through the Presenter', async () => {
|
|
58
|
+
const result = await tester.callAction('system', 'health');
|
|
59
|
+
|
|
60
|
+
expect(result.isError).toBe(false);
|
|
61
|
+
expect(result.data).toHaveProperty('status');
|
|
62
|
+
expect(result.data).toHaveProperty('uptime');
|
|
63
|
+
expect(result.data).toHaveProperty('version');
|
|
64
|
+
expect(result.data).toHaveProperty('timestamp');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should strip undeclared fields (tenant must NOT leak)', async () => {
|
|
68
|
+
const result = await tester.callAction('system', 'health');
|
|
69
|
+
|
|
70
|
+
expect(result.isError).toBe(false);
|
|
71
|
+
// The handler returns 'tenant' but the Presenter schema
|
|
72
|
+
// does not declare it → stripped by Egress Firewall
|
|
73
|
+
expect(result.data).not.toHaveProperty('tenant');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should include JIT system rules from .describe()', async () => {
|
|
77
|
+
const result = await tester.callAction('system', 'health');
|
|
78
|
+
|
|
79
|
+
expect(result.systemRules.length).toBeGreaterThan(0);
|
|
80
|
+
expect(result.systemRules.some(
|
|
81
|
+
(r: string) => r.includes('uptime') || r.includes('Uptime')
|
|
82
|
+
)).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('Echo Tool', () => {
|
|
87
|
+
it('should echo the message back', async () => {
|
|
88
|
+
const result = await tester.callAction('system', 'echo', {
|
|
89
|
+
message: 'hello fusion',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(result.isError).toBe(false);
|
|
93
|
+
expect(result.data).toHaveProperty('echo', 'hello fusion');
|
|
94
|
+
expect(result.data).toHaveProperty('receivedAt');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
98
|
`;
|
|
99
99
|
}
|
|
100
100
|
//# sourceMappingURL=testing.js.map
|
|
@@ -4,63 +4,63 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/** Generate `src/tools/system/health.ts` — Health check with Presenter */
|
|
6
6
|
export function healthToolTs() {
|
|
7
|
-
return `/**
|
|
8
|
-
* System Health Tool — Full MVA Pipeline Example
|
|
9
|
-
*
|
|
10
|
-
* Demonstrates:
|
|
11
|
-
* - f.tool() with automatic context typing
|
|
12
|
-
* - Presenter integration (Egress Firewall)
|
|
13
|
-
* - readOnly annotation for LLM optimization
|
|
14
|
-
* - export default for autoDiscover()
|
|
15
|
-
*/
|
|
16
|
-
import { f } from '../../fusion.js';
|
|
17
|
-
import { SystemPresenter } from '../../presenters/SystemPresenter.js';
|
|
18
|
-
|
|
19
|
-
export default f.tool({
|
|
20
|
-
name: 'system.health',
|
|
21
|
-
description: 'Real-time server health status',
|
|
22
|
-
readOnly: true,
|
|
23
|
-
returns: SystemPresenter,
|
|
24
|
-
handler: async ({ ctx }) => {
|
|
25
|
-
// Return raw data — the Presenter validates, strips
|
|
26
|
-
// undeclared fields, injects rules, and renders UI.
|
|
27
|
-
return {
|
|
28
|
-
status: 'healthy',
|
|
29
|
-
uptime: process.uptime(),
|
|
30
|
-
version: '0.1.0',
|
|
31
|
-
timestamp: new Date().toISOString(),
|
|
32
|
-
tenant: ctx.tenantId,
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
});
|
|
7
|
+
return `/**
|
|
8
|
+
* System Health Tool — Full MVA Pipeline Example
|
|
9
|
+
*
|
|
10
|
+
* Demonstrates:
|
|
11
|
+
* - f.tool() with automatic context typing
|
|
12
|
+
* - Presenter integration (Egress Firewall)
|
|
13
|
+
* - readOnly annotation for LLM optimization
|
|
14
|
+
* - export default for autoDiscover()
|
|
15
|
+
*/
|
|
16
|
+
import { f } from '../../fusion.js';
|
|
17
|
+
import { SystemPresenter } from '../../presenters/SystemPresenter.js';
|
|
18
|
+
|
|
19
|
+
export default f.tool({
|
|
20
|
+
name: 'system.health',
|
|
21
|
+
description: 'Real-time server health status',
|
|
22
|
+
readOnly: true,
|
|
23
|
+
returns: SystemPresenter,
|
|
24
|
+
handler: async ({ ctx }) => {
|
|
25
|
+
// Return raw data — the Presenter validates, strips
|
|
26
|
+
// undeclared fields, injects rules, and renders UI.
|
|
27
|
+
return {
|
|
28
|
+
status: 'healthy',
|
|
29
|
+
uptime: process.uptime(),
|
|
30
|
+
version: '0.1.0',
|
|
31
|
+
timestamp: new Date().toISOString(),
|
|
32
|
+
tenant: ctx.tenantId,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
36
|
`;
|
|
37
37
|
}
|
|
38
38
|
/** Generate `src/tools/system/echo.ts` — Simple echo tool */
|
|
39
39
|
export function echoToolTs() {
|
|
40
|
-
return `/**
|
|
41
|
-
* Echo Tool — Connectivity Testing
|
|
42
|
-
*
|
|
43
|
-
* Minimal tool without a Presenter. Uses success() for
|
|
44
|
-
* a raw JSON response. Useful for verifying the MCP
|
|
45
|
-
* connection is alive.
|
|
46
|
-
*/
|
|
47
|
-
import { f } from '../../fusion.js';
|
|
48
|
-
import { success } from '@vinkius-core/mcp-fusion';
|
|
49
|
-
|
|
50
|
-
export default f.tool({
|
|
51
|
-
name: 'system.echo',
|
|
52
|
-
description: 'Echo a message back (connectivity test)',
|
|
53
|
-
readOnly: true,
|
|
54
|
-
input: {
|
|
55
|
-
message: { type: 'string', description: 'Message to echo back' },
|
|
56
|
-
},
|
|
57
|
-
handler: async ({ input }) => {
|
|
58
|
-
return success({
|
|
59
|
-
echo: input.message,
|
|
60
|
-
receivedAt: new Date().toISOString(),
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
});
|
|
40
|
+
return `/**
|
|
41
|
+
* Echo Tool — Connectivity Testing
|
|
42
|
+
*
|
|
43
|
+
* Minimal tool without a Presenter. Uses success() for
|
|
44
|
+
* a raw JSON response. Useful for verifying the MCP
|
|
45
|
+
* connection is alive.
|
|
46
|
+
*/
|
|
47
|
+
import { f } from '../../fusion.js';
|
|
48
|
+
import { success } from '@vinkius-core/mcp-fusion';
|
|
49
|
+
|
|
50
|
+
export default f.tool({
|
|
51
|
+
name: 'system.echo',
|
|
52
|
+
description: 'Echo a message back (connectivity test)',
|
|
53
|
+
readOnly: true,
|
|
54
|
+
input: {
|
|
55
|
+
message: { type: 'string', description: 'Message to echo back' },
|
|
56
|
+
},
|
|
57
|
+
handler: async ({ input }) => {
|
|
58
|
+
return success({
|
|
59
|
+
echo: input.message,
|
|
60
|
+
receivedAt: new Date().toISOString(),
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
64
|
`;
|
|
65
65
|
}
|
|
66
66
|
//# sourceMappingURL=tools.js.map
|