@haneinfo/mcp-server 2.1.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/LICENSE +14 -0
- package/dist/discovery-push.service.d.ts +18 -0
- package/dist/discovery-push.service.d.ts.map +1 -0
- package/dist/discovery-push.service.js +66 -0
- package/dist/discovery-push.service.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-tool.decorator.d.ts +17 -0
- package/dist/mcp-tool.decorator.d.ts.map +1 -0
- package/dist/mcp-tool.decorator.js +35 -0
- package/dist/mcp-tool.decorator.js.map +1 -0
- package/dist/mcp-tool.registry.d.ts +37 -0
- package/dist/mcp-tool.registry.d.ts.map +1 -0
- package/dist/mcp-tool.registry.js +189 -0
- package/dist/mcp-tool.registry.js.map +1 -0
- package/dist/mcp.controller.d.ts +16 -0
- package/dist/mcp.controller.d.ts.map +1 -0
- package/dist/mcp.controller.js +115 -0
- package/dist/mcp.controller.js.map +1 -0
- package/dist/mcp.module.d.ts +9 -0
- package/dist/mcp.module.d.ts.map +1 -0
- package/dist/mcp.module.js +39 -0
- package/dist/mcp.module.js.map +1 -0
- package/dist/mcp.service.d.ts +22 -0
- package/dist/mcp.service.d.ts.map +1 -0
- package/dist/mcp.service.js +174 -0
- package/dist/mcp.service.js.map +1 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +62 -0
- package/dist/plugin.js.map +1 -0
- package/dist/request-state.d.ts +41 -0
- package/dist/request-state.d.ts.map +1 -0
- package/dist/request-state.js +58 -0
- package/dist/request-state.js.map +1 -0
- package/dist/stateful-mcp-handler.d.ts +19 -0
- package/dist/stateful-mcp-handler.d.ts.map +1 -0
- package/dist/stateful-mcp-handler.js +159 -0
- package/dist/stateful-mcp-handler.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/haneinfo.plugin.json +37 -0
- package/package.json +66 -0
- package/plugin.d.ts +3 -0
- package/plugin.js +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 Haneinfo. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the proprietary and
|
|
4
|
+
confidential property of Haneinfo. No part of the Software may be copied, modified, merged,
|
|
5
|
+
published, distributed, sublicensed, or sold without the prior written permission of Haneinfo.
|
|
6
|
+
|
|
7
|
+
The Software is provided for internal use by Haneinfo and its authorized personnel only, and is
|
|
8
|
+
NOT licensed for external distribution or open-source use.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
11
|
+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
12
|
+
NONINFRINGEMENT. IN NO EVENT SHALL HANEINFO BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
13
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
|
14
|
+
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
+
import { McpToolRegistry } from './mcp-tool.registry';
|
|
3
|
+
/**
|
|
4
|
+
* Opt-in, best-effort push of this app's tool catalog to the 023 discovery service
|
|
5
|
+
* (dev_docs 023 §2.1, T-9700). Only apps with `DISCOVERY_PUSH_URL` + `DISCOVERY_PUSH_TOKEN`
|
|
6
|
+
* set push anything — every other app is unaffected. Push happens once, at boot: a deploy
|
|
7
|
+
* already restarts the process, so "push at deploy time" (the cadence 023 §2.1 calls for)
|
|
8
|
+
* falls out of `OnApplicationBootstrap` without needing a scheduler dependency. A failed
|
|
9
|
+
* push is logged and swallowed — the discovery catalog is a convenience directory, not a
|
|
10
|
+
* dependency this app's own requests should ever fail on.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DiscoveryPushService implements OnApplicationBootstrap {
|
|
13
|
+
private readonly registry;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
constructor(registry: McpToolRegistry);
|
|
16
|
+
onApplicationBootstrap(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=discovery-push.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-push.service.d.ts","sourceRoot":"","sources":["../src/discovery-push.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;;;;;GAQG;AACH,qBACa,oBAAqB,YAAW,sBAAsB;IAGrD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;gBAEnC,QAAQ,EAAE,eAAe;IAEhD,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CA8B9C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var DiscoveryPushService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.DiscoveryPushService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const mcp_tool_registry_1 = require("./mcp-tool.registry");
|
|
16
|
+
/**
|
|
17
|
+
* Opt-in, best-effort push of this app's tool catalog to the 023 discovery service
|
|
18
|
+
* (dev_docs 023 §2.1, T-9700). Only apps with `DISCOVERY_PUSH_URL` + `DISCOVERY_PUSH_TOKEN`
|
|
19
|
+
* set push anything — every other app is unaffected. Push happens once, at boot: a deploy
|
|
20
|
+
* already restarts the process, so "push at deploy time" (the cadence 023 §2.1 calls for)
|
|
21
|
+
* falls out of `OnApplicationBootstrap` without needing a scheduler dependency. A failed
|
|
22
|
+
* push is logged and swallowed — the discovery catalog is a convenience directory, not a
|
|
23
|
+
* dependency this app's own requests should ever fail on.
|
|
24
|
+
*/
|
|
25
|
+
let DiscoveryPushService = DiscoveryPushService_1 = class DiscoveryPushService {
|
|
26
|
+
constructor(registry) {
|
|
27
|
+
this.registry = registry;
|
|
28
|
+
this.logger = new common_1.Logger(DiscoveryPushService_1.name);
|
|
29
|
+
}
|
|
30
|
+
async onApplicationBootstrap() {
|
|
31
|
+
const pushUrl = process.env.DISCOVERY_PUSH_URL;
|
|
32
|
+
const pushToken = process.env.DISCOVERY_PUSH_TOKEN;
|
|
33
|
+
if (!pushUrl || !pushToken)
|
|
34
|
+
return;
|
|
35
|
+
const publicBaseUrl = process.env.PUBLIC_BASE_URL;
|
|
36
|
+
const body = {
|
|
37
|
+
toolCatalogSnapshot: this.registry.getCatalogSnapshot(),
|
|
38
|
+
};
|
|
39
|
+
if (publicBaseUrl) {
|
|
40
|
+
body.mcpEndpointUrl = `${publicBaseUrl}/mcp`;
|
|
41
|
+
body.metadataEndpointUrl = `${publicBaseUrl}/metadata/schema`;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch(`${pushUrl.replace(/\/$/, '')}/discovery/push`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'content-type': 'application/json', 'x-discovery-push-token': pushToken },
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
signal: AbortSignal.timeout(5000),
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
this.logger.warn(`Discovery catalog push failed: HTTP ${res.status}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.logger.log('Discovery catalog push succeeded');
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
this.logger.warn(`Discovery catalog push failed: ${String(e)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.DiscoveryPushService = DiscoveryPushService;
|
|
62
|
+
exports.DiscoveryPushService = DiscoveryPushService = DiscoveryPushService_1 = __decorate([
|
|
63
|
+
(0, common_1.Injectable)(),
|
|
64
|
+
__metadata("design:paramtypes", [mcp_tool_registry_1.McpToolRegistry])
|
|
65
|
+
], DiscoveryPushService);
|
|
66
|
+
//# sourceMappingURL=discovery-push.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-push.service.js","sourceRoot":"","sources":["../src/discovery-push.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4E;AAC5E,2DAAsD;AAEtD;;;;;;;;GAQG;AAEI,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAG/B,YAA6B,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAFrC,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEP,CAAC;IAE1D,KAAK,CAAC,sBAAsB;QAC1B,MAA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AAnCY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAI4B,mCAAe;GAH3C,oBAAoB,CAmChC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { MCP_TOOLS, type McpToolsPort } from '@haneinfo/plugin-api';
|
|
2
|
+
export * from './discovery-push.service';
|
|
3
|
+
export * from './mcp.controller';
|
|
4
|
+
export * from './mcp.module';
|
|
5
|
+
export * from './mcp.service';
|
|
6
|
+
export * from './mcp-tool.decorator';
|
|
7
|
+
export * from './mcp-tool.registry';
|
|
8
|
+
export * from './stateful-mcp-handler';
|
|
9
|
+
export * from './types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpE,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.MCP_TOOLS = void 0;
|
|
18
|
+
var plugin_api_1 = require("@haneinfo/plugin-api");
|
|
19
|
+
Object.defineProperty(exports, "MCP_TOOLS", { enumerable: true, get: function () { return plugin_api_1.MCP_TOOLS; } });
|
|
20
|
+
__exportStar(require("./discovery-push.service"), exports);
|
|
21
|
+
__exportStar(require("./mcp.controller"), exports);
|
|
22
|
+
__exportStar(require("./mcp.module"), exports);
|
|
23
|
+
__exportStar(require("./mcp.service"), exports);
|
|
24
|
+
__exportStar(require("./mcp-tool.decorator"), exports);
|
|
25
|
+
__exportStar(require("./mcp-tool.registry"), exports);
|
|
26
|
+
__exportStar(require("./stateful-mcp-handler"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAoE;AAA3D,uGAAA,SAAS,OAAA;AAClB,2DAAyC;AACzC,mDAAiC;AACjC,+CAA6B;AAC7B,gDAA8B;AAC9B,uDAAqC;AACrC,sDAAoC;AACpC,yDAAuC;AACvC,0CAAwB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
import type { McpToolRegistry } from './mcp-tool.registry';
|
|
3
|
+
export declare const MCP_TOOL_PROVIDERS = "MCP_TOOL_PROVIDERS";
|
|
4
|
+
export interface McpToolOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: ZodType;
|
|
8
|
+
outputSchema?: ZodType;
|
|
9
|
+
/** Required, even for an intentionally public tool (pass `[]` explicitly) -- an omitted
|
|
10
|
+
* value used to default to `[]` silently, so a tool that simply forgot to declare its
|
|
11
|
+
* scopes was callable by every API key regardless of what scopes it actually holds. */
|
|
12
|
+
requiredScopes: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function McpTool(options: McpToolOptions): MethodDecorator;
|
|
15
|
+
/** Scans an instance for @McpTool()-decorated methods and registers them with the registry. */
|
|
16
|
+
export declare function registerMcpToolsFromInstance(instance: object, registry: McpToolRegistry): void;
|
|
17
|
+
//# sourceMappingURL=mcp-tool.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.decorator.d.ts","sourceRoot":"","sources":["../src/mcp-tool.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;2FAEuF;IACvF,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe,CAIhE;AAED,+FAA+F;AAC/F,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CA6B9F"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_TOOL_PROVIDERS = void 0;
|
|
4
|
+
exports.McpTool = McpTool;
|
|
5
|
+
exports.registerMcpToolsFromInstance = registerMcpToolsFromInstance;
|
|
6
|
+
exports.MCP_TOOL_PROVIDERS = 'MCP_TOOL_PROVIDERS';
|
|
7
|
+
function McpTool(options) {
|
|
8
|
+
return (target, propertyKey) => {
|
|
9
|
+
Reflect.defineMetadata('mcp:tool', options, target, propertyKey);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Scans an instance for @McpTool()-decorated methods and registers them with the registry. */
|
|
13
|
+
function registerMcpToolsFromInstance(instance, registry) {
|
|
14
|
+
const proto = Object.getPrototypeOf(instance);
|
|
15
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
16
|
+
const options = Reflect.getMetadata('mcp:tool', proto, key);
|
|
17
|
+
if (!options)
|
|
18
|
+
continue;
|
|
19
|
+
const method = instance[key];
|
|
20
|
+
if (typeof method !== 'function')
|
|
21
|
+
continue;
|
|
22
|
+
if (!Array.isArray(options.requiredScopes)) {
|
|
23
|
+
throw new Error(`@McpTool "${options.name}" must declare requiredScopes explicitly (pass [] for an intentionally public tool)`);
|
|
24
|
+
}
|
|
25
|
+
registry.registerTool({
|
|
26
|
+
name: options.name,
|
|
27
|
+
description: options.description,
|
|
28
|
+
inputSchema: options.inputSchema,
|
|
29
|
+
outputSchema: options.outputSchema,
|
|
30
|
+
requiredScopes: options.requiredScopes,
|
|
31
|
+
handler: (args, ctx) => method.call(instance, args, ctx),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mcp-tool.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.decorator.js","sourceRoot":"","sources":["../src/mcp-tool.decorator.ts"],"names":[],"mappings":";;;AAiBA,0BAIC;AAGD,oEA6BC;AAjDY,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAavD,SAAgB,OAAO,CAAC,OAAuB;IAC7C,OAAO,CAAC,MAAc,EAAE,WAA4B,E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pCallContext, McpToolDefinition } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the app-level tool prefix from `MCP_TOOL_PREFIX` (002 env var convention). Returns
|
|
5
|
+
* `undefined` during the dual-registration transition window for apps that haven't set it yet
|
|
6
|
+
* (dev_docs 023 §2.2) — in that case only the unprefixed legacy name is registered.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getConfiguredToolPrefix(): string | undefined;
|
|
9
|
+
export declare function classifyToolAsReadOnly(requiredScopes: string[]): boolean;
|
|
10
|
+
export interface McpCatalogEntry extends McpCatalogEntryPort {
|
|
11
|
+
}
|
|
12
|
+
export declare class McpToolRegistry implements McpToolsPort<McpToolDefinition> {
|
|
13
|
+
private readonly scopeMatcher?;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private readonly toolMap;
|
|
16
|
+
private readonly logicalTools;
|
|
17
|
+
constructor(scopeMatcher?: ScopeMatcherPort | undefined);
|
|
18
|
+
listTools(ctx: McpCallContext): McpToolDefinition[];
|
|
19
|
+
getTool(name: string): McpToolDefinition | undefined;
|
|
20
|
+
getToolCount(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Registers `tool` under its own name, and — when `MCP_TOOL_PREFIX` is configured — also
|
|
23
|
+
* under `<prefix>_<name>` pointing at the same handler/scopes (dual registration, dev_docs
|
|
24
|
+
* 023 §2.2). Both names stay registered through the transition window; only the unprefixed
|
|
25
|
+
* name is dropped once it's retired (dev_docs 023 §6.5).
|
|
26
|
+
*/
|
|
27
|
+
registerTool(tool: McpToolDefinition): void;
|
|
28
|
+
/**
|
|
29
|
+
* External-facing catalog snapshot (023 §2.1 discovery push, T-9700) — one entry per
|
|
30
|
+
* logical tool, named however an outside caller would actually have to call it (prefixed
|
|
31
|
+
* when `MCP_TOOL_PREFIX` is configured, bare name during the transition window otherwise).
|
|
32
|
+
*/
|
|
33
|
+
getCatalogSnapshot(): McpCatalogEntry[];
|
|
34
|
+
private matchesScope;
|
|
35
|
+
private registerSingle;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=mcp-tool.registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.registry.d.ts","sourceRoot":"","sources":["../src/mcp-tool.registry.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAOjE;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAS5D;AAyDD,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAMxE;AAKD,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;CAAG;AAE/D,qBACa,eAAgB,YAAW,YAAY,CAAC,iBAAiB,CAAC;IAWnE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAVhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAIhE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA2B;gBAKrC,YAAY,CAAC,EAAE,gBAAgB,YAAA;IAGlD,SAAS,CAAC,GAAG,EAAE,cAAc,GAAG,iBAAiB,EAAE;IAMnD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAIpD,YAAY,IAAI,MAAM;IAItB;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAU3C;;;;OAIG;IACH,kBAAkB,IAAI,eAAe,EAAE;IAUvC,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,cAAc;CAMvB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
var McpToolRegistry_1;
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.McpToolRegistry = void 0;
|
|
50
|
+
exports.getConfiguredToolPrefix = getConfiguredToolPrefix;
|
|
51
|
+
exports.classifyToolAsReadOnly = classifyToolAsReadOnly;
|
|
52
|
+
const pluginApiContract = __importStar(require("@haneinfo/plugin-api"));
|
|
53
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
54
|
+
const common_1 = require("@nestjs/common");
|
|
55
|
+
// Cross-app tool naming prefix (dev_docs 002 "consistent app prefixes across apps", dev_docs 023 §2.2) —
|
|
56
|
+
// only `[a-zA-Z0-9_-]` is allowed because the prefixed name must also satisfy MCP tool-calling
|
|
57
|
+
// name constraints (dev_docs 023 §3.1).
|
|
58
|
+
const TOOL_PREFIX_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
59
|
+
/**
|
|
60
|
+
* Reads the app-level tool prefix from `MCP_TOOL_PREFIX` (002 env var convention). Returns
|
|
61
|
+
* `undefined` during the dual-registration transition window for apps that haven't set it yet
|
|
62
|
+
* (dev_docs 023 §2.2) — in that case only the unprefixed legacy name is registered.
|
|
63
|
+
*/
|
|
64
|
+
function getConfiguredToolPrefix() {
|
|
65
|
+
const prefix = process.env.MCP_TOOL_PREFIX;
|
|
66
|
+
if (!prefix)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (!TOOL_PREFIX_PATTERN.test(prefix)) {
|
|
69
|
+
throw new Error(`MCP_TOOL_PREFIX="${prefix}" is invalid — must match ${TOOL_PREFIX_PATTERN} (dev_docs 023 §2.2).`);
|
|
70
|
+
}
|
|
71
|
+
return prefix;
|
|
72
|
+
}
|
|
73
|
+
// Read/write action classification (dev_docs 002 "scope action read/write classification rules",
|
|
74
|
+
// dev_docs 023 §2.3/§6.4) — this is the source `readOnlyHint` in mcp.service.ts is derived
|
|
75
|
+
// from, and what the AI Agent Team app's single-write-per-invocation check (023 §3.5) relies
|
|
76
|
+
// on. A tool with no declared scopes can't be classified, so it fails closed as a write tool
|
|
77
|
+
// (same fail-closed posture as `actingUserId` in types.ts).
|
|
78
|
+
const READ_ACTIONS = new Set(['read', 'list', 'get']);
|
|
79
|
+
// Compatibility bridge for apps that consume this package from a local file before the
|
|
80
|
+
// plugin-api release carrying the shared scope contract is published. Released installations use
|
|
81
|
+
// plugin-api's implementation; the local fallback follows the same fail-closed grammar.
|
|
82
|
+
function parseScopeContract(scope) {
|
|
83
|
+
const shared = pluginApiContract.parseScope;
|
|
84
|
+
if (shared)
|
|
85
|
+
return shared(scope);
|
|
86
|
+
const separator = scope.lastIndexOf(':');
|
|
87
|
+
if (separator <= 0 || separator === scope.length - 1)
|
|
88
|
+
return null;
|
|
89
|
+
const resource = scope.slice(0, separator);
|
|
90
|
+
const action = scope.slice(separator + 1);
|
|
91
|
+
if (resource.split(':').some((segment) => segment.length === 0 || /[\s*]/.test(segment)) ||
|
|
92
|
+
/\s/.test(action) ||
|
|
93
|
+
action.includes(':')) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return { resource, action };
|
|
97
|
+
}
|
|
98
|
+
function matchScopeContract(grantedScopes, requiredScope) {
|
|
99
|
+
const shared = pluginApiContract.matchScope;
|
|
100
|
+
if (shared)
|
|
101
|
+
return shared(grantedScopes, requiredScope);
|
|
102
|
+
if (grantedScopes.includes('*'))
|
|
103
|
+
return true;
|
|
104
|
+
const required = parseScopeContract(requiredScope);
|
|
105
|
+
if (!required || required.action === '*')
|
|
106
|
+
return false;
|
|
107
|
+
return grantedScopes.some((grantedScope) => {
|
|
108
|
+
const granted = parseScopeContract(grantedScope);
|
|
109
|
+
return (granted !== null &&
|
|
110
|
+
granted.resource === required.resource &&
|
|
111
|
+
(granted.action === '*' || granted.action === required.action));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function classifyToolAsReadOnly(requiredScopes) {
|
|
115
|
+
if (requiredScopes.length === 0)
|
|
116
|
+
return false;
|
|
117
|
+
return requiredScopes.every((scope) => {
|
|
118
|
+
const parsed = parseScopeContract(scope);
|
|
119
|
+
return parsed !== null && READ_ACTIONS.has(parsed.action);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
let McpToolRegistry = McpToolRegistry_1 = class McpToolRegistry {
|
|
123
|
+
constructor(scopeMatcher) {
|
|
124
|
+
this.scopeMatcher = scopeMatcher;
|
|
125
|
+
this.logger = new common_1.Logger(McpToolRegistry_1.name);
|
|
126
|
+
this.toolMap = new Map();
|
|
127
|
+
// One entry per @McpTool(), pre-prefixing — the source list getCatalogSnapshot() derives
|
|
128
|
+
// its external-facing names from, so a dual-registered tool isn't reported twice (023 §2.1
|
|
129
|
+
// discovery push, T-9700).
|
|
130
|
+
this.logicalTools = [];
|
|
131
|
+
}
|
|
132
|
+
listTools(ctx) {
|
|
133
|
+
return Array.from(this.toolMap.values()).filter((tool) => tool.requiredScopes.every((scope) => this.matchesScope(ctx.scopes, scope)));
|
|
134
|
+
}
|
|
135
|
+
getTool(name) {
|
|
136
|
+
return this.toolMap.get(name);
|
|
137
|
+
}
|
|
138
|
+
getToolCount() {
|
|
139
|
+
return this.toolMap.size;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Registers `tool` under its own name, and — when `MCP_TOOL_PREFIX` is configured — also
|
|
143
|
+
* under `<prefix>_<name>` pointing at the same handler/scopes (dual registration, dev_docs
|
|
144
|
+
* 023 §2.2). Both names stay registered through the transition window; only the unprefixed
|
|
145
|
+
* name is dropped once it's retired (dev_docs 023 §6.5).
|
|
146
|
+
*/
|
|
147
|
+
registerTool(tool) {
|
|
148
|
+
this.registerSingle(tool);
|
|
149
|
+
this.logicalTools.push(tool);
|
|
150
|
+
const prefix = getConfiguredToolPrefix();
|
|
151
|
+
if (prefix) {
|
|
152
|
+
this.registerSingle({ ...tool, name: `${prefix}_${tool.name}` });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* External-facing catalog snapshot (023 §2.1 discovery push, T-9700) — one entry per
|
|
157
|
+
* logical tool, named however an outside caller would actually have to call it (prefixed
|
|
158
|
+
* when `MCP_TOOL_PREFIX` is configured, bare name during the transition window otherwise).
|
|
159
|
+
*/
|
|
160
|
+
getCatalogSnapshot() {
|
|
161
|
+
const prefix = getConfiguredToolPrefix();
|
|
162
|
+
return this.logicalTools.map((tool) => ({
|
|
163
|
+
name: prefix ? `${prefix}_${tool.name}` : tool.name,
|
|
164
|
+
description: tool.description,
|
|
165
|
+
requiredScopes: tool.requiredScopes,
|
|
166
|
+
readOnlyHint: classifyToolAsReadOnly(tool.requiredScopes),
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
matchesScope(grantedScopes, requiredScope) {
|
|
170
|
+
if (this.scopeMatcher) {
|
|
171
|
+
return this.scopeMatcher.matches(grantedScopes, requiredScope);
|
|
172
|
+
}
|
|
173
|
+
return matchScopeContract(grantedScopes, requiredScope);
|
|
174
|
+
}
|
|
175
|
+
registerSingle(tool) {
|
|
176
|
+
if (this.toolMap.has(tool.name)) {
|
|
177
|
+
this.logger.log(`Tool "${tool.name}" re-registered, overriding the previous definition`);
|
|
178
|
+
}
|
|
179
|
+
this.toolMap.set(tool.name, tool);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
exports.McpToolRegistry = McpToolRegistry;
|
|
183
|
+
exports.McpToolRegistry = McpToolRegistry = McpToolRegistry_1 = __decorate([
|
|
184
|
+
(0, common_1.Injectable)(),
|
|
185
|
+
__param(0, (0, common_1.Optional)()),
|
|
186
|
+
__param(0, (0, common_1.Inject)(plugin_api_1.SCOPE_MATCHER)),
|
|
187
|
+
__metadata("design:paramtypes", [Object])
|
|
188
|
+
], McpToolRegistry);
|
|
189
|
+
//# sourceMappingURL=mcp-tool.registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.registry.js","sourceRoot":"","sources":["../src/mcp-tool.registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,0DASC;AAyDD,wDAMC;AA5FD,wEAA0D;AAC1D,qDAK8B;AAC9B,2CAAsE;AAGtE,yGAAyG;AACzG,+FAA+F;AAC/F,wCAAwC;AACxC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,SAAgB,uBAAuB;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,oBAAoB,MAAM,6BAA6B,mBAAmB,uBAAuB,CAClG,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iGAAiG;AACjG,2FAA2F;AAC3F,6FAA6F;AAC7F,6FAA6F;AAC7F,4DAA4D;AAC5D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAItD,uFAAuF;AACvF,iGAAiG;AACjG,wFAAwF;AACxF,SAAS,kBAAkB,CAAC,KAAa;IACvC,MAAM,MAAM,GACV,iBAGD,CAAC,UAAU,CAAC;IACb,IAAI,MAAM;QAAE,O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AAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,IAAI,qDAAqD,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AAxEY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,0BAAa,CAAC,CAAA;;GAVb,eAAe,CAwE3B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import { McpService } from './mcp.service';
|
|
3
|
+
import { McpToolRegistry } from './mcp-tool.registry';
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the correlation workflow id from request headers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractWorkflowId(headers: Record<string, unknown>): string | null;
|
|
8
|
+
export declare class McpController {
|
|
9
|
+
private readonly mcpService;
|
|
10
|
+
private readonly registry;
|
|
11
|
+
private readonly nodeHandler;
|
|
12
|
+
constructor(mcpService: McpService, registry: McpToolRegistry);
|
|
13
|
+
handlePost(req: Request, res: Response): Promise<void>;
|
|
14
|
+
getHealth(challenge?: string): object;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=mcp.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.controller.d.ts","sourceRoot":"","sources":["../src/mcp.controller.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGjF;AAID,qBACa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAJ3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAGV,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,eAAe;IAOtC,UAAU,CAAQ,GAAG,EAAE,OAAO,EAA+B,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwDhG,SAAS,CAAqB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;CAW1D"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.McpController = void 0;
|
|
16
|
+
exports.extractWorkflowId = extractWorkflowId;
|
|
17
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
18
|
+
const plugin_host_nest_1 = require("@haneinfo/plugin-host-nest");
|
|
19
|
+
const node_1 = require("@modelcontextprotocol/node");
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const mcp_service_1 = require("./mcp.service");
|
|
22
|
+
const mcp_tool_registry_1 = require("./mcp-tool.registry");
|
|
23
|
+
const WORKFLOW_ID_HEADER = 'x-haneinfo-workflow-id';
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the correlation workflow id from request headers.
|
|
26
|
+
*/
|
|
27
|
+
function extractWorkflowId(headers) {
|
|
28
|
+
const value = headers[WORKFLOW_ID_HEADER];
|
|
29
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
30
|
+
}
|
|
31
|
+
// MCP is for external agents (n8n, AI clients) authenticated via machine authentication (M2M API key) —
|
|
32
|
+
// same auth layer as the rest of the M2M surface (dev_docs 001 "MCP Server transport").
|
|
33
|
+
let McpController = class McpController {
|
|
34
|
+
constructor(mcpService, registry) {
|
|
35
|
+
this.mcpService = mcpService;
|
|
36
|
+
this.registry = registry;
|
|
37
|
+
this.nodeHandler = (0, node_1.toNodeHandler)(this.mcpService.getHandler());
|
|
38
|
+
}
|
|
39
|
+
async handlePost(req, res) {
|
|
40
|
+
const user = req.user;
|
|
41
|
+
const isApiKey = user ? (0, plugin_api_1.isMachinePrincipal)(user) : false;
|
|
42
|
+
const scopes = user && 'scopes' in user && Array.isArray(user.scopes) ? user.scopes : [];
|
|
43
|
+
const actingUserId = user ? (0, plugin_api_1.actingUserIdOf)(user) : null;
|
|
44
|
+
const ctx = {
|
|
45
|
+
scopes,
|
|
46
|
+
isApiKey,
|
|
47
|
+
principalKind: 'm2m-api-key',
|
|
48
|
+
roleNames: user?.roleNames ?? [],
|
|
49
|
+
actingUserId,
|
|
50
|
+
sub: user?.sub ?? '',
|
|
51
|
+
workflowId: extractWorkflowId((req.headers ?? {})),
|
|
52
|
+
};
|
|
53
|
+
if (!(0, node_1.hostHeaderValidation)(readAllowedHostnames('MCP_ALLOWED_HOSTNAMES'))(req, res)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!(0, node_1.originValidation)(readAllowedHostnames('MCP_ALLOWED_ORIGIN_HOSTNAMES'))(req, res)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const authInfo = {
|
|
60
|
+
token: 'haneinfo-api-key',
|
|
61
|
+
clientId: ctx.sub,
|
|
62
|
+
scopes: ctx.scopes,
|
|
63
|
+
extra: { mcpCallContext: ctx },
|
|
64
|
+
};
|
|
65
|
+
req.auth = authInfo;
|
|
66
|
+
await this.nodeHandler(req, res, req.body);
|
|
67
|
+
}
|
|
68
|
+
// The optional `challenge` echo lets the 023 discovery service (§2.1) verify control of an
|
|
69
|
+
// app's MCP endpoint before accepting an endpoint-location change: it calls this same,
|
|
70
|
+
// already-public, unauthenticated route with a nonce and checks the value comes back
|
|
71
|
+
// unchanged, proving the caller can reach whatever is actually serving that URL. Read-only
|
|
72
|
+
// and harmless -- it doesn't grant access to anything, so no new auth surface is needed.
|
|
73
|
+
getHealth(challenge) {
|
|
74
|
+
return {
|
|
75
|
+
status: 'ok',
|
|
76
|
+
serverInfo: {
|
|
77
|
+
name: process.env.npm_package_name ?? 'haneinfo-app',
|
|
78
|
+
version: process.env.npm_package_version ?? '1.0.0',
|
|
79
|
+
},
|
|
80
|
+
toolCount: this.registry.getToolCount(),
|
|
81
|
+
...(challenge !== undefined ? { challenge } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.McpController = McpController;
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, common_1.All)(),
|
|
88
|
+
(0, common_1.UseGuards)(plugin_host_nest_1.MachineAuthGuard),
|
|
89
|
+
__param(0, (0, common_1.Req)()),
|
|
90
|
+
__param(1, (0, common_1.Res)({ passthrough: false })),
|
|
91
|
+
__metadata("design:type", Function),
|
|
92
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
93
|
+
__metadata("design:returntype", Promise)
|
|
94
|
+
], McpController.prototype, "handlePost", null);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, common_1.Get)('health'),
|
|
97
|
+
__param(0, (0, common_1.Query)('challenge')),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [String]),
|
|
100
|
+
__metadata("design:returntype", Object)
|
|
101
|
+
], McpController.prototype, "getHealth", null);
|
|
102
|
+
exports.McpController = McpController = __decorate([
|
|
103
|
+
(0, common_1.Controller)('mcp'),
|
|
104
|
+
__metadata("design:paramtypes", [mcp_service_1.McpService,
|
|
105
|
+
mcp_tool_registry_1.McpToolRegistry])
|
|
106
|
+
], McpController);
|
|
107
|
+
function readAllowedHostnames(variableName) {
|
|
108
|
+
const configured = process.env[variableName]
|
|
109
|
+
?.split(',')
|
|
110
|
+
.map((hostname) => hostname.trim())
|
|
111
|
+
.filter((hostname) => hostname.length > 0);
|
|
112
|
+
// An absent allowlist must fail closed; deployment configuration owns the public host names.
|
|
113
|
+
return configured ?? [];
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=mcp.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.controller.js","sourceRoot":"","sources":["../src/mcp.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBA,8CAGC;AAxBD,qDAA0F;AAC1F,iEAA8D;AAC9D,qDAMoC;AAEpC,2CAAkF;AAElF,+CAA2C;AAC3C,2DAAsD;AAGtD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAEpD;;GAEG;AACH,SAAgB,iBAAiB,CAAC,OAAgC;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAA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Aa;IADzB,IAAA,mBAAU,EAAC,KAAK,CAAC;qCAKe,wBAAU;QACZ,mCAAe;GALjC,aAAa,CA+EzB;AAED,SAAS,oBAAoB,CAAC,YAAoB;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;QAC1C,EAAE,KAAK,CAAC,GAAG,CAAC;SACX,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SAClC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE7C,6FAA6F;IAC7F,OAAO,UAAU,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Context Protocol Server capability module (051 PL4-06).
|
|
3
|
+
*
|
|
4
|
+
* The module is deliberately scoped. Feature modules that inject `McpToolRegistry` must import it
|
|
5
|
+
* explicitly or import a generated plugin composition module that exports it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class McpModule {
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=mcp.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.module.d.ts","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,qBAWa,SAAS;CAAG"}
|