@ibm/ibmi-mcp-server 0.1.2 → 0.3.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/README.md +2178 -46
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +57 -24
- package/dist/config/index.js.map +1 -1
- package/dist/config/resolver.d.ts.map +1 -1
- package/dist/config/resolver.js.map +1 -1
- package/dist/ibmi-mcp-server/auth/httpAuthEndpoint.js +1 -1
- package/dist/ibmi-mcp-server/services/connectionPool.js +2 -2
- package/dist/ibmi-mcp-server/tools/executeSql.tool.d.ts +80 -0
- package/dist/ibmi-mcp-server/tools/executeSql.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/executeSql.tool.js +356 -0
- package/dist/ibmi-mcp-server/tools/executeSql.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/generateSql.tool.d.ts +36 -0
- package/dist/ibmi-mcp-server/tools/generateSql.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/generateSql.tool.js +281 -0
- package/dist/ibmi-mcp-server/tools/generateSql.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/index.d.ts +85 -0
- package/dist/ibmi-mcp-server/tools/index.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/index.js +21 -0
- package/dist/ibmi-mcp-server/tools/index.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/config/configParser.d.ts +9 -0
- package/dist/ibmi-mcp-server/utils/config/configParser.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/configParser.js +58 -0
- package/dist/ibmi-mcp-server/utils/config/configParser.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolConfigBuilder.js +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolConfigBuilder.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolDefinitions.d.ts +4 -4
- package/dist/ibmi-mcp-server/utils/config/toolDefinitions.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolDefinitions.js +7 -8
- package/dist/ibmi-mcp-server/utils/config/toolDefinitions.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolFactory.d.ts +0 -8
- package/dist/ibmi-mcp-server/utils/config/toolFactory.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolFactory.js +0 -31
- package/dist/ibmi-mcp-server/utils/config/toolFactory.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolsetManager.d.ts +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolsetManager.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/config/toolsetManager.js +2 -2
- package/dist/ibmi-mcp-server/utils/config/toolsetManager.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/language/document.d.ts +26 -0
- package/dist/ibmi-mcp-server/utils/language/document.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/document.js +318 -0
- package/dist/ibmi-mcp-server/utils/language/document.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/statement.d.ts +43 -0
- package/dist/ibmi-mcp-server/utils/language/statement.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/statement.js +796 -0
- package/dist/ibmi-mcp-server/utils/language/statement.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/tokens.d.ts +32 -0
- package/dist/ibmi-mcp-server/utils/language/tokens.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/tokens.js +532 -0
- package/dist/ibmi-mcp-server/utils/language/tokens.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/types.d.ts +138 -0
- package/dist/ibmi-mcp-server/utils/language/types.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/language/types.js +93 -0
- package/dist/ibmi-mcp-server/utils/language/types.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.d.ts +48 -0
- package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.js +93 -0
- package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.d.ts +35 -59
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js +108 -288
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.d.ts +54 -0
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.js +91 -0
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.js.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/index.d.ts +13 -2
- package/dist/mcp-server/tools/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/index.js +29 -9
- package/dist/mcp-server/tools/index.js.map +1 -1
- package/dist/mcp-server/tools/utils/index.d.ts +7 -0
- package/dist/mcp-server/tools/utils/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/index.js +7 -0
- package/dist/mcp-server/tools/utils/index.js.map +1 -0
- package/dist/mcp-server/tools/utils/tool-factory.d.ts +129 -0
- package/dist/mcp-server/tools/utils/tool-factory.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/tool-factory.js +179 -0
- package/dist/mcp-server/tools/utils/tool-factory.js.map +1 -0
- package/dist/mcp-server/tools/utils/types.d.ts +117 -0
- package/dist/mcp-server/tools/utils/types.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/types.js +11 -0
- package/dist/mcp-server/tools/utils/types.js.map +1 -0
- package/dist/mcp-server/transports/core/cleanupTransformStream.d.ts +26 -0
- package/dist/mcp-server/transports/core/cleanupTransformStream.d.ts.map +1 -0
- package/dist/mcp-server/transports/core/cleanupTransformStream.js +60 -0
- package/dist/mcp-server/transports/core/cleanupTransformStream.js.map +1 -0
- package/dist/mcp-server/transports/core/statefulTransportManager.d.ts +1 -1
- package/dist/mcp-server/transports/core/statefulTransportManager.d.ts.map +1 -1
- package/dist/mcp-server/transports/core/statefulTransportManager.js +50 -40
- package/dist/mcp-server/transports/core/statefulTransportManager.js.map +1 -1
- package/dist/mcp-server/transports/core/statelessTransportManager.d.ts +2 -13
- package/dist/mcp-server/transports/core/statelessTransportManager.d.ts.map +1 -1
- package/dist/mcp-server/transports/core/statelessTransportManager.js +35 -62
- package/dist/mcp-server/transports/core/statelessTransportManager.js.map +1 -1
- package/dist/mcp-server/transports/core/transportRequest.d.ts +1 -2
- package/dist/mcp-server/transports/core/transportRequest.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/mcpTransportMiddleware.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/mcpTransportMiddleware.js +1 -3
- package/dist/mcp-server/transports/http/mcpTransportMiddleware.js.map +1 -1
- package/dist/utils/internal/logger.d.ts +5 -0
- package/dist/utils/internal/logger.d.ts.map +1 -1
- package/dist/utils/internal/logger.js +65 -36
- package/dist/utils/internal/logger.js.map +1 -1
- package/package.json +29 -23
- package/dist/ibmi-mcp-server/tools/executeSql/index.d.ts +0 -9
- package/dist/ibmi-mcp-server/tools/executeSql/index.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/executeSql/index.js +0 -9
- package/dist/ibmi-mcp-server/tools/executeSql/index.js.map +0 -1
- package/dist/ibmi-mcp-server/tools/executeSql/logic.d.ts +0 -51
- package/dist/ibmi-mcp-server/tools/executeSql/logic.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/executeSql/logic.js +0 -179
- package/dist/ibmi-mcp-server/tools/executeSql/logic.js.map +0 -1
- package/dist/ibmi-mcp-server/tools/executeSql/registration.d.ts +0 -52
- package/dist/ibmi-mcp-server/tools/executeSql/registration.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/executeSql/registration.js +0 -161
- package/dist/ibmi-mcp-server/tools/executeSql/registration.js.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/index.d.ts +0 -13
- package/dist/ibmi-mcp-server/tools/generateSql/index.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/index.js +0 -13
- package/dist/ibmi-mcp-server/tools/generateSql/index.js.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/logic.d.ts +0 -64
- package/dist/ibmi-mcp-server/tools/generateSql/logic.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/logic.js +0 -190
- package/dist/ibmi-mcp-server/tools/generateSql/logic.js.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/registration.d.ts +0 -18
- package/dist/ibmi-mcp-server/tools/generateSql/registration.d.ts.map +0 -1
- package/dist/ibmi-mcp-server/tools/generateSql/registration.js +0 -64
- package/dist/ibmi-mcp-server/tools/generateSql/registration.js.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/index.d.ts +0 -8
- package/dist/mcp-server/tools/catFactFetcher/index.d.ts.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/index.js +0 -8
- package/dist/mcp-server/tools/catFactFetcher/index.js.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/logic.d.ts +0 -52
- package/dist/mcp-server/tools/catFactFetcher/logic.d.ts.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/logic.js +0 -95
- package/dist/mcp-server/tools/catFactFetcher/logic.js.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/registration.d.ts +0 -9
- package/dist/mcp-server/tools/catFactFetcher/registration.d.ts.map +0 -1
- package/dist/mcp-server/tools/catFactFetcher/registration.js +0 -43
- package/dist/mcp-server/tools/catFactFetcher/registration.js.map +0 -1
- package/dist/mcp-server/tools/echoTool/index.d.ts +0 -13
- package/dist/mcp-server/tools/echoTool/index.d.ts.map +0 -1
- package/dist/mcp-server/tools/echoTool/index.js +0 -13
- package/dist/mcp-server/tools/echoTool/index.js.map +0 -1
- package/dist/mcp-server/tools/echoTool/logic.d.ts +0 -69
- package/dist/mcp-server/tools/echoTool/logic.d.ts.map +0 -1
- package/dist/mcp-server/tools/echoTool/logic.js +0 -119
- package/dist/mcp-server/tools/echoTool/logic.js.map +0 -1
- package/dist/mcp-server/tools/echoTool/registration.d.ts +0 -9
- package/dist/mcp-server/tools/echoTool/registration.d.ts.map +0 -1
- package/dist/mcp-server/tools/echoTool/registration.js +0 -45
- package/dist/mcp-server/tools/echoTool/registration.js.map +0 -1
- package/dist/mcp-server/tools/imageTest/index.d.ts +0 -7
- package/dist/mcp-server/tools/imageTest/index.d.ts.map +0 -1
- package/dist/mcp-server/tools/imageTest/index.js +0 -7
- package/dist/mcp-server/tools/imageTest/index.js.map +0 -1
- package/dist/mcp-server/tools/imageTest/logic.d.ts +0 -27
- package/dist/mcp-server/tools/imageTest/logic.d.ts.map +0 -1
- package/dist/mcp-server/tools/imageTest/logic.js +0 -44
- package/dist/mcp-server/tools/imageTest/logic.js.map +0 -1
- package/dist/mcp-server/tools/imageTest/registration.d.ts +0 -9
- package/dist/mcp-server/tools/imageTest/registration.d.ts.map +0 -1
- package/dist/mcp-server/tools/imageTest/registration.js +0 -49
- package/dist/mcp-server/tools/imageTest/registration.js.map +0 -1
- package/dist/mcp-server/tools/utils/tool-utils.d.ts +0 -43
- package/dist/mcp-server/tools/utils/tool-utils.d.ts.map +0 -1
- package/dist/mcp-server/tools/utils/tool-utils.js +0 -44
- package/dist/mcp-server/tools/utils/tool-utils.js.map +0 -1
- package/dist/mcp-server/transports/core/headerUtils.d.ts +0 -27
- package/dist/mcp-server/transports/core/headerUtils.d.ts.map +0 -1
- package/dist/mcp-server/transports/core/headerUtils.js +0 -53
- package/dist/mcp-server/transports/core/headerUtils.js.map +0 -1
- package/dist/mcp-server/transports/core/honoNodeBridge.d.ts +0 -77
- package/dist/mcp-server/transports/core/honoNodeBridge.d.ts.map +0 -1
- package/dist/mcp-server/transports/core/honoNodeBridge.js +0 -150
- package/dist/mcp-server/transports/core/honoNodeBridge.js.map +0 -1
- package/dist/services/duck-db/duckDBConnectionManager.d.ts +0 -55
- package/dist/services/duck-db/duckDBConnectionManager.d.ts.map +0 -1
- package/dist/services/duck-db/duckDBConnectionManager.js +0 -184
- package/dist/services/duck-db/duckDBConnectionManager.js.map +0 -1
- package/dist/services/duck-db/duckDBQueryExecutor.d.ts +0 -18
- package/dist/services/duck-db/duckDBQueryExecutor.d.ts.map +0 -1
- package/dist/services/duck-db/duckDBQueryExecutor.js +0 -115
- package/dist/services/duck-db/duckDBQueryExecutor.js.map +0 -1
- package/dist/services/duck-db/duckDBService.d.ts +0 -27
- package/dist/services/duck-db/duckDBService.d.ts.map +0 -1
- package/dist/services/duck-db/duckDBService.js +0 -151
- package/dist/services/duck-db/duckDBService.js.map +0 -1
- package/dist/services/duck-db/types.d.ts +0 -135
- package/dist/services/duck-db/types.d.ts.map +0 -1
- package/dist/services/duck-db/types.js +0 -6
- package/dist/services/duck-db/types.js.map +0 -1
- package/dist/services/llm-providers/openRouterProvider.d.ts +0 -36
- package/dist/services/llm-providers/openRouterProvider.d.ts.map +0 -1
- package/dist/services/llm-providers/openRouterProvider.js +0 -235
- package/dist/services/llm-providers/openRouterProvider.js.map +0 -1
- package/dist/services/supabase/supabaseClient.d.ts +0 -25
- package/dist/services/supabase/supabaseClient.d.ts.map +0 -1
- package/dist/services/supabase/supabaseClient.js +0 -68
- package/dist/services/supabase/supabaseClient.js.map +0 -1
- package/dist/storage/duckdbExample.d.ts +0 -8
- package/dist/storage/duckdbExample.d.ts.map +0 -1
- package/dist/storage/duckdbExample.js +0 -197
- package/dist/storage/duckdbExample.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { config, environment } from "./config/index.js";
|
|
|
13
13
|
import { initializeAndStartServer } from "./mcp-server/server.js";
|
|
14
14
|
import { requestContextService } from "./utils/index.js";
|
|
15
15
|
import { logFatal, logOperationError, logOperationStart, logOperationSuccess, } from "./utils/internal/logging-helpers.js";
|
|
16
|
-
import { logger } from "./utils/internal/logger.js";
|
|
16
|
+
import { logger, reinitializeLogger } from "./utils/internal/logger.js";
|
|
17
17
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
18
|
import http from "http";
|
|
19
19
|
import { statSync, existsSync } from "fs";
|
|
@@ -30,6 +30,7 @@ async function listToolsetsCommand() {
|
|
|
30
30
|
try {
|
|
31
31
|
// Apply CLI overrides to get the correct tools path
|
|
32
32
|
applyCliOverrides(cliArgs);
|
|
33
|
+
reinitializeLogger();
|
|
33
34
|
if (!config.toolsYamlPath) {
|
|
34
35
|
logger.error("❌ No YAML tools configuration found.");
|
|
35
36
|
logger.error(" Use --tools <path> to specify YAML tools configuration or set TOOLS_YAML_PATH environment variable.\n");
|
|
@@ -145,6 +146,8 @@ if (cliArgs.tools) {
|
|
|
145
146
|
}
|
|
146
147
|
// Apply CLI overrides directly to global config so downstream modules see changes
|
|
147
148
|
applyCliOverrides(cliArgs);
|
|
149
|
+
// Reinitialize logger with updated config (especially transport mode from CLI)
|
|
150
|
+
reinitializeLogger();
|
|
148
151
|
// Log overrides if provided
|
|
149
152
|
if (cliArgs.tools) {
|
|
150
153
|
logger.info(`ℹ Using tools path: ${config.toolsYamlPath}`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,2EAA2E;AAC3E,mDAAmD;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,QAAQ,E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registration Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Registers all factory pattern tools with the MCP server.
|
|
5
|
+
* Each tool is registered directly using registerToolFromDefinition.
|
|
6
|
+
*
|
|
7
|
+
* @module tools
|
|
8
|
+
*/
|
|
1
9
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
/**
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Registers all factory pattern tools with the MCP server.
|
|
12
|
+
* Tools are defined in the allToolDefinitions array.
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerAllTools(server: McpServer): Promise<void>;
|
|
4
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAUzE;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BvE"}
|
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registration Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Registers all factory pattern tools with the MCP server.
|
|
5
|
+
* Each tool is registered directly using registerToolFromDefinition.
|
|
6
|
+
*
|
|
7
|
+
* @module tools
|
|
8
|
+
*/
|
|
9
|
+
import { allToolDefinitions } from "../../ibmi-mcp-server/tools/index.js";
|
|
10
|
+
import { registerToolFromDefinition } from "./utils/tool-factory.js";
|
|
11
|
+
import { logger, requestContextService } from "../../utils/index.js";
|
|
2
12
|
import { logOperationStart, logOperationSuccess, } from "../../utils/internal/logging-helpers.js";
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
|
|
13
|
+
import { config } from "../../config/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Registers all factory pattern tools with the MCP server.
|
|
16
|
+
* Tools are defined in the allToolDefinitions array.
|
|
17
|
+
*/
|
|
18
|
+
export async function registerAllTools(server) {
|
|
6
19
|
const context = requestContextService.createRequestContext({
|
|
7
|
-
operation: "
|
|
20
|
+
operation: "RegisterAllTools",
|
|
8
21
|
});
|
|
9
|
-
logOperationStart(context,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
logOperationStart(context, `Registering ${allToolDefinitions.length} factory pattern tools`);
|
|
23
|
+
for (const toolDef of allToolDefinitions) {
|
|
24
|
+
if (toolDef.name === "execute_sql" && !config.ibmi_enableExecuteSql) {
|
|
25
|
+
// Skip execute_sql tool if disabled via IBMI_ENABLE_EXECUTE_SQL
|
|
26
|
+
logger.debug(context, "Skipping registration of execute_sql tool (IBMI_ENABLE_EXECUTE_SQL=false)");
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
await registerToolFromDefinition(server, toolDef);
|
|
30
|
+
}
|
|
31
|
+
logOperationSuccess(context, `Successfully registered ${allToolDefinitions.length} factory pattern tools`);
|
|
32
|
+
}
|
|
13
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAiB;IACtD,MAAM,OAAO,GAAG,qBAAqB,CAAC,oBAAoB,CAAC;QACzD,SAAS,EAAE,kBAAkB;KAC9B,CAAC,CAAC;IAEH,iBAAiB,CACf,OAAO,EACP,eAAe,kBAAkB,CAAC,MAAM,wBAAwB,CACjE,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,kBAAkB,EAAE,CAAC;QACzC,IAAI,OAAO,CAAC,IAAI,KAAK,aAAa,IAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC;YACpE,gEAAgE;YAChE,MAAM,CAAC,KAAK,CACV,OAAO,EACP,2EAA2E,CAC5E,CAAC;YACF,SAAS;QACX,CAAC;QACD,MAAM,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,mBAAmB,CACjB,OAAO,EACP,2BAA2B,kBAAkB,CAAC,MAAM,wBAAwB,CAC7E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,cAAc,EACd,eAAe,EACf,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,2BAA2B;AAC3B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registration Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a factory pattern for creating and registering MCP tools with minimal boilerplate.
|
|
5
|
+
* Handles validation, registration, error handling, and response formatting automatically.
|
|
6
|
+
*
|
|
7
|
+
* @module tool-factory
|
|
8
|
+
* @feature 001-tool-factory
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
13
|
+
import { type RequestContext } from "../../../utils/index.js";
|
|
14
|
+
import type { ToolDefinition, ResponseFormatter, SdkContext } from "./types.js";
|
|
15
|
+
/**
|
|
16
|
+
* Zod schema for validating tool definitions at registration time.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
19
|
+
name: z.ZodString;
|
|
20
|
+
description: z.ZodString;
|
|
21
|
+
inputSchema: z.ZodType<z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
22
|
+
[x: string]: any;
|
|
23
|
+
}, {
|
|
24
|
+
[x: string]: any;
|
|
25
|
+
}>, z.ZodTypeDef, z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
26
|
+
[x: string]: any;
|
|
27
|
+
}, {
|
|
28
|
+
[x: string]: any;
|
|
29
|
+
}>>;
|
|
30
|
+
outputSchema: z.ZodType<z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
}, {
|
|
33
|
+
[x: string]: any;
|
|
34
|
+
}>, z.ZodTypeDef, z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
35
|
+
[x: string]: any;
|
|
36
|
+
}, {
|
|
37
|
+
[x: string]: any;
|
|
38
|
+
}>>;
|
|
39
|
+
logic: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
|
|
40
|
+
title: z.ZodOptional<z.ZodString>;
|
|
41
|
+
responseFormatter: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
42
|
+
annotations: z.ZodOptional<z.ZodObject<{
|
|
43
|
+
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
readOnlyHint?: boolean | undefined;
|
|
48
|
+
openWorldHint?: boolean | undefined;
|
|
49
|
+
destructiveHint?: boolean | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
readOnlyHint?: boolean | undefined;
|
|
52
|
+
openWorldHint?: boolean | undefined;
|
|
53
|
+
destructiveHint?: boolean | undefined;
|
|
54
|
+
}>>;
|
|
55
|
+
enabled: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
inputSchema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
60
|
+
[x: string]: any;
|
|
61
|
+
}, {
|
|
62
|
+
[x: string]: any;
|
|
63
|
+
}>;
|
|
64
|
+
outputSchema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
65
|
+
[x: string]: any;
|
|
66
|
+
}, {
|
|
67
|
+
[x: string]: any;
|
|
68
|
+
}>;
|
|
69
|
+
logic: (...args: unknown[]) => unknown;
|
|
70
|
+
enabled?: boolean | ((...args: unknown[]) => unknown) | undefined;
|
|
71
|
+
title?: string | undefined;
|
|
72
|
+
annotations?: {
|
|
73
|
+
readOnlyHint?: boolean | undefined;
|
|
74
|
+
openWorldHint?: boolean | undefined;
|
|
75
|
+
destructiveHint?: boolean | undefined;
|
|
76
|
+
} | undefined;
|
|
77
|
+
responseFormatter?: ((...args: unknown[]) => unknown) | undefined;
|
|
78
|
+
}, {
|
|
79
|
+
name: string;
|
|
80
|
+
description: string;
|
|
81
|
+
inputSchema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
82
|
+
[x: string]: any;
|
|
83
|
+
}, {
|
|
84
|
+
[x: string]: any;
|
|
85
|
+
}>;
|
|
86
|
+
outputSchema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
87
|
+
[x: string]: any;
|
|
88
|
+
}, {
|
|
89
|
+
[x: string]: any;
|
|
90
|
+
}>;
|
|
91
|
+
logic: (...args: unknown[]) => unknown;
|
|
92
|
+
enabled?: boolean | ((...args: unknown[]) => unknown) | undefined;
|
|
93
|
+
title?: string | undefined;
|
|
94
|
+
annotations?: {
|
|
95
|
+
readOnlyHint?: boolean | undefined;
|
|
96
|
+
openWorldHint?: boolean | undefined;
|
|
97
|
+
destructiveHint?: boolean | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
responseFormatter?: ((...args: unknown[]) => unknown) | undefined;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a standardized MCP tool handler.
|
|
103
|
+
* This factory encapsulates context creation, performance measurement,
|
|
104
|
+
* error handling, and response formatting. It separates the app's internal
|
|
105
|
+
* RequestContext from the SDK's context (SdkContext).
|
|
106
|
+
*
|
|
107
|
+
* @param toolName - The name of the tool for logging and metrics
|
|
108
|
+
* @param logic - The core business logic function
|
|
109
|
+
* @param responseFormatter - Optional custom formatter (defaults to JSON)
|
|
110
|
+
* @returns A handler function compatible with the MCP SDK's tool callback
|
|
111
|
+
*/
|
|
112
|
+
export declare function createHandler<TInput, TOutput>(toolName: string, logic: (input: TInput, appContext: RequestContext, sdkContext: SdkContext) => Promise<TOutput>, responseFormatter?: ResponseFormatter<TOutput>): (input: TInput, extra: unknown) => Promise<CallToolResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Factory function for creating tool definitions.
|
|
115
|
+
* Provides type inference and acts as the main entry point for tool authors.
|
|
116
|
+
*
|
|
117
|
+
* @param definition - The tool configuration
|
|
118
|
+
* @returns The same tool definition (for type inference)
|
|
119
|
+
*/
|
|
120
|
+
export declare function defineTool<TInputShape extends z.ZodRawShape, TOutputShape extends z.ZodRawShape>(definition: ToolDefinition<TInputShape, TOutputShape>): ToolDefinition<TInputShape, TOutputShape>;
|
|
121
|
+
/**
|
|
122
|
+
* Registers a single tool from its definition.
|
|
123
|
+
* Accepts any tool definition shape to support arrays of mixed tool types.
|
|
124
|
+
*
|
|
125
|
+
* @param server - The MCP server instance
|
|
126
|
+
* @param toolDef - The tool definition to register
|
|
127
|
+
*/
|
|
128
|
+
export declare function registerToolFromDefinition(server: McpServer, toolDef: ToolDefinition<any, any>): Promise<void>;
|
|
129
|
+
//# sourceMappingURL=tool-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/tool-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAa,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,KAAK,EACV,cAAc,EAEd,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AAMpB;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgC/B,CAAC;AAkBH;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAC3C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,CACL,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,UAAU,KACnB,OAAO,CAAC,OAAO,CAAC,EACrB,iBAAiB,GAAE,iBAAiB,CAAC,OAAO,CAA0D,GACrG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,cAAc,CAAC,CAiD5D;AAMD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,WAAW,SAAS,CAAC,CAAC,WAAW,EACjC,YAAY,SAAS,CAAC,CAAC,WAAW,EAElC,UAAU,EAAE,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,GACpD,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAI3C;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,SAAS,EAEjB,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CA6Ef"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registration Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a factory pattern for creating and registering MCP tools with minimal boilerplate.
|
|
5
|
+
* Handles validation, registration, error handling, and response formatting automatically.
|
|
6
|
+
*
|
|
7
|
+
* @module tool-factory
|
|
8
|
+
* @feature 001-tool-factory
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { JsonRpcErrorCode } from "../../../types-global/errors.js";
|
|
12
|
+
import { ErrorHandler, requestContextService, measureToolExecution, } from "../../../utils/index.js";
|
|
13
|
+
import { logOperationStart, logOperationSuccess, } from "../../../utils/internal/logging-helpers.js";
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Validation Schema
|
|
16
|
+
// =============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for validating tool definitions at registration time.
|
|
19
|
+
*/
|
|
20
|
+
export const ToolDefinitionSchema = z.object({
|
|
21
|
+
name: z
|
|
22
|
+
.string()
|
|
23
|
+
.min(1, "Tool name is required")
|
|
24
|
+
.regex(/^[a-z][a-z0-9_]*$/, "Tool name must be snake_case (lowercase letters, numbers, underscores)"),
|
|
25
|
+
description: z.string().min(1, "Tool description is required"),
|
|
26
|
+
inputSchema: z.custom((val) => val instanceof z.ZodObject, {
|
|
27
|
+
message: "inputSchema must be a Zod object schema",
|
|
28
|
+
}),
|
|
29
|
+
outputSchema: z.custom((val) => val instanceof z.ZodObject, {
|
|
30
|
+
message: "outputSchema must be a Zod object schema",
|
|
31
|
+
}),
|
|
32
|
+
logic: z.function(),
|
|
33
|
+
title: z.string().optional(),
|
|
34
|
+
responseFormatter: z.function().optional(),
|
|
35
|
+
annotations: z
|
|
36
|
+
.object({
|
|
37
|
+
readOnlyHint: z.boolean().optional(),
|
|
38
|
+
destructiveHint: z.boolean().optional(),
|
|
39
|
+
openWorldHint: z.boolean().optional(),
|
|
40
|
+
})
|
|
41
|
+
.optional(),
|
|
42
|
+
enabled: z.union([z.boolean(), z.function()]).optional(),
|
|
43
|
+
});
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Default Response Formatter
|
|
46
|
+
// =============================================================================
|
|
47
|
+
/**
|
|
48
|
+
* Default formatter for successful responses.
|
|
49
|
+
* Returns a simple JSON representation of the result.
|
|
50
|
+
*/
|
|
51
|
+
const defaultResponseFormatter = (result) => [
|
|
52
|
+
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
53
|
+
];
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// Handler Factory
|
|
56
|
+
// =============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Creates a standardized MCP tool handler.
|
|
59
|
+
* This factory encapsulates context creation, performance measurement,
|
|
60
|
+
* error handling, and response formatting. It separates the app's internal
|
|
61
|
+
* RequestContext from the SDK's context (SdkContext).
|
|
62
|
+
*
|
|
63
|
+
* @param toolName - The name of the tool for logging and metrics
|
|
64
|
+
* @param logic - The core business logic function
|
|
65
|
+
* @param responseFormatter - Optional custom formatter (defaults to JSON)
|
|
66
|
+
* @returns A handler function compatible with the MCP SDK's tool callback
|
|
67
|
+
*/
|
|
68
|
+
export function createHandler(toolName, logic, responseFormatter = defaultResponseFormatter) {
|
|
69
|
+
return async (input, callContext) => {
|
|
70
|
+
// Cast the SDK context to our specific SdkContext type
|
|
71
|
+
const sdkContext = callContext;
|
|
72
|
+
const sessionId = typeof sdkContext?.sessionId === "string"
|
|
73
|
+
? sdkContext.sessionId
|
|
74
|
+
: undefined;
|
|
75
|
+
// Create the application's internal logger/tracing context
|
|
76
|
+
const appContext = requestContextService.createRequestContext({
|
|
77
|
+
parentContext: sdkContext,
|
|
78
|
+
operation: "HandleToolRequest",
|
|
79
|
+
additionalContext: { toolName, sessionId, input },
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const result = await measureToolExecution(toolName, () => logic(input, appContext, sdkContext), input);
|
|
83
|
+
return {
|
|
84
|
+
structuredContent: result,
|
|
85
|
+
content: responseFormatter(result),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const mcpError = ErrorHandler.handleError(error, {
|
|
90
|
+
operation: `tool:${toolName}`,
|
|
91
|
+
context: appContext,
|
|
92
|
+
input,
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
isError: true,
|
|
96
|
+
content: [{ type: "text", text: `Error: ${mcpError.message}` }],
|
|
97
|
+
structuredContent: {
|
|
98
|
+
code: mcpError.code,
|
|
99
|
+
message: mcpError.message,
|
|
100
|
+
details: mcpError.details,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// =============================================================================
|
|
107
|
+
// Factory Functions
|
|
108
|
+
// =============================================================================
|
|
109
|
+
/**
|
|
110
|
+
* Factory function for creating tool definitions.
|
|
111
|
+
* Provides type inference and acts as the main entry point for tool authors.
|
|
112
|
+
*
|
|
113
|
+
* @param definition - The tool configuration
|
|
114
|
+
* @returns The same tool definition (for type inference)
|
|
115
|
+
*/
|
|
116
|
+
export function defineTool(definition) {
|
|
117
|
+
// Validate the definition
|
|
118
|
+
ToolDefinitionSchema.parse(definition);
|
|
119
|
+
return definition;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Registers a single tool from its definition.
|
|
123
|
+
* Accepts any tool definition shape to support arrays of mixed tool types.
|
|
124
|
+
*
|
|
125
|
+
* @param server - The MCP server instance
|
|
126
|
+
* @param toolDef - The tool definition to register
|
|
127
|
+
*/
|
|
128
|
+
export async function registerToolFromDefinition(server,
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
toolDef) {
|
|
131
|
+
const registrationContext = requestContextService.createRequestContext({
|
|
132
|
+
operation: "RegisterTool",
|
|
133
|
+
toolName: toolDef.name,
|
|
134
|
+
});
|
|
135
|
+
logOperationStart(registrationContext, `Registering tool: '${toolDef.name}'`);
|
|
136
|
+
await ErrorHandler.tryCatch(async () => {
|
|
137
|
+
// Check if tool is enabled
|
|
138
|
+
const enabled = toolDef.enabled === undefined
|
|
139
|
+
? true
|
|
140
|
+
: typeof toolDef.enabled === "function"
|
|
141
|
+
? toolDef.enabled()
|
|
142
|
+
: toolDef.enabled;
|
|
143
|
+
if (!enabled) {
|
|
144
|
+
logOperationSuccess(registrationContext, `Tool '${toolDef.name}' is disabled, skipping registration`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Prepare metadata
|
|
148
|
+
const title = toolDef.title ||
|
|
149
|
+
toolDef.name
|
|
150
|
+
.split("_")
|
|
151
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
152
|
+
.join(" ");
|
|
153
|
+
const annotations = {
|
|
154
|
+
readOnlyHint: toolDef.annotations?.readOnlyHint ?? false,
|
|
155
|
+
destructiveHint: toolDef.annotations?.destructiveHint ?? false,
|
|
156
|
+
openWorldHint: toolDef.annotations?.openWorldHint ?? false,
|
|
157
|
+
};
|
|
158
|
+
// Use custom formatter or default
|
|
159
|
+
const responseFormatter = toolDef.responseFormatter || defaultResponseFormatter;
|
|
160
|
+
// Create handler using the factory
|
|
161
|
+
const handler = createHandler(toolDef.name, toolDef.logic, responseFormatter);
|
|
162
|
+
// Register with MCP server
|
|
163
|
+
// Use .shape to extract raw schema like YAML tools do
|
|
164
|
+
server.registerTool(toolDef.name, {
|
|
165
|
+
title,
|
|
166
|
+
description: toolDef.description,
|
|
167
|
+
inputSchema: toolDef.inputSchema.shape,
|
|
168
|
+
outputSchema: toolDef.outputSchema.shape,
|
|
169
|
+
annotations,
|
|
170
|
+
}, handler);
|
|
171
|
+
logOperationSuccess(registrationContext, `Tool '${toolDef.name}' registered successfully`);
|
|
172
|
+
}, {
|
|
173
|
+
operation: `RegisteringTool_${toolDef.name}`,
|
|
174
|
+
context: registrationContext,
|
|
175
|
+
errorCode: JsonRpcErrorCode.InitializationFailed,
|
|
176
|
+
critical: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=tool-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/tool-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAa,MAAM,KAAK,CAAC;AAMnC,OAAO,EAAE,gBAAgB,EAAY,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,GAErB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,4CAA4C,CAAC;AAQpD,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3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
|
|
1
|
+
/**
|
|
2
|
+
* Tool Factory Contracts
|
|
3
|
+
*
|
|
4
|
+
* TypeScript interfaces defining the contract between tool authors
|
|
5
|
+
* and the registration system.
|
|
6
|
+
*
|
|
7
|
+
* @module tool-factory
|
|
8
|
+
* @feature 001-tool-factory
|
|
9
|
+
*/
|
|
10
|
+
import type { z, ZodObject, ZodRawShape } from "zod";
|
|
11
|
+
import type { ContentBlock } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
13
|
+
import type { ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
14
|
+
import type { RequestContext } from "../../../utils/index.js";
|
|
15
|
+
/**
|
|
16
|
+
* Defines the function signature for formatting a successful tool logic result
|
|
17
|
+
* into content blocks for display.
|
|
18
|
+
* @template TOutput The type of the successful output from the logic.
|
|
19
|
+
* @param result The successful output from the tool's logic function.
|
|
20
|
+
* @returns An array of ContentBlocks for the MCP client to display.
|
|
21
|
+
*/
|
|
22
|
+
export type ResponseFormatter<TOutput> = (result: TOutput) => ContentBlock[];
|
|
23
|
+
/**
|
|
24
|
+
* A type alias for the SDK's `RequestHandlerExtra` context, making it more
|
|
25
|
+
* specific and easier to reference in our tool logic signatures.
|
|
26
|
+
* Provides access to protocol-level capabilities like cancellation, notifications, and auth.
|
|
27
|
+
*/
|
|
28
|
+
export type SdkContext = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
29
|
+
/**
|
|
30
|
+
* Function signature for tool business logic.
|
|
31
|
+
* Receives validated input, application context, and SDK context, returns structured output.
|
|
32
|
+
*
|
|
33
|
+
* @template TInput - Input type inferred from inputSchema
|
|
34
|
+
* @template TOutput - Output type inferred from outputSchema
|
|
35
|
+
*/
|
|
36
|
+
export type ToolLogicFn<TInput, TOutput> = (params: TInput, appContext: RequestContext, sdkContext: SdkContext) => Promise<TOutput>;
|
|
37
|
+
/**
|
|
38
|
+
* MCP protocol hints for LLM decision-making.
|
|
39
|
+
* All fields are optional and default to false.
|
|
40
|
+
*/
|
|
41
|
+
export interface ToolAnnotations {
|
|
42
|
+
/** Tool only reads data, no side effects */
|
|
43
|
+
readOnlyHint?: boolean;
|
|
44
|
+
/** Tool may permanently delete or modify data */
|
|
45
|
+
destructiveHint?: boolean;
|
|
46
|
+
/** Tool makes external API or network calls */
|
|
47
|
+
openWorldHint?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Developer-facing interface for declaring an MCP tool.
|
|
51
|
+
*
|
|
52
|
+
* @template TInputShape - Zod shape for input schema
|
|
53
|
+
* @template TOutputShape - Zod shape for output schema
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const myTool = defineTool({
|
|
58
|
+
* name: "my_tool",
|
|
59
|
+
* description: "Does something useful",
|
|
60
|
+
* inputSchema: z.object({ query: z.string() }),
|
|
61
|
+
* outputSchema: z.object({ result: z.string() }),
|
|
62
|
+
* logic: async ({ query }, appContext) => {
|
|
63
|
+
* logger.debug({ ...appContext, query }, 'Processing query');
|
|
64
|
+
* return { result: `Processed: ${query}` };
|
|
65
|
+
* },
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export interface ToolDefinition<TInputShape extends ZodRawShape = ZodRawShape, TOutputShape extends ZodRawShape = ZodRawShape> {
|
|
70
|
+
/**
|
|
71
|
+
* Unique tool identifier.
|
|
72
|
+
* Convention: snake_case (e.g., "describe_sql_object")
|
|
73
|
+
*/
|
|
74
|
+
name: string;
|
|
75
|
+
/**
|
|
76
|
+
* LLM-facing description of tool capabilities.
|
|
77
|
+
* Should clearly explain what the tool does and when to use it.
|
|
78
|
+
*/
|
|
79
|
+
description: string;
|
|
80
|
+
/**
|
|
81
|
+
* Zod schema validating tool input.
|
|
82
|
+
* Input is validated before logic function is called.
|
|
83
|
+
*/
|
|
84
|
+
inputSchema: ZodObject<TInputShape>;
|
|
85
|
+
/**
|
|
86
|
+
* Zod schema defining expected output structure.
|
|
87
|
+
* Used for documentation and type inference.
|
|
88
|
+
*/
|
|
89
|
+
outputSchema: ZodObject<TOutputShape>;
|
|
90
|
+
/**
|
|
91
|
+
* Pure async function implementing tool behavior.
|
|
92
|
+
* Receives validated input and application context, returns structured output.
|
|
93
|
+
*/
|
|
94
|
+
logic: ToolLogicFn<z.infer<ZodObject<TInputShape>>, z.infer<ZodObject<TOutputShape>>>;
|
|
95
|
+
/**
|
|
96
|
+
* Human-readable title for UI display.
|
|
97
|
+
* Defaults to formatted tool name if not provided.
|
|
98
|
+
*/
|
|
99
|
+
title?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Custom output formatter.
|
|
102
|
+
* Defaults to JSON serialization with text summary.
|
|
103
|
+
*/
|
|
104
|
+
responseFormatter?: ResponseFormatter<z.infer<ZodObject<TOutputShape>>>;
|
|
105
|
+
/**
|
|
106
|
+
* MCP safety hints for LLM decision-making.
|
|
107
|
+
* All hints default to false if not specified.
|
|
108
|
+
*/
|
|
109
|
+
annotations?: ToolAnnotations;
|
|
110
|
+
/**
|
|
111
|
+
* Conditional registration control.
|
|
112
|
+
* Set to false or return false from function to skip registration.
|
|
113
|
+
* Defaults to true (tool is registered).
|
|
114
|
+
*/
|
|
115
|
+
enabled?: boolean | (() => boolean);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAC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