@kya-os/mcp-i 1.2.7 → 1.2.8
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/compiler/compiler-context.d.ts +2 -0
- package/dist/compiler/config/injection.d.ts +1 -1
- package/dist/compiler/config/injection.js +34 -14
- package/dist/compiler/get-webpack-config/get-injected-variables.js +2 -2
- package/dist/compiler/get-webpack-config/plugins.js +3 -3
- package/dist/compiler/index.js +1 -0
- package/dist/runtime/adapter-express.js +1 -1
- package/dist/runtime/adapter-nextjs.js +1 -1
- package/dist/runtime/adapters/nextjs/index.js +6 -1
- package/dist/runtime/demo.js +3 -3
- package/dist/runtime/http.js +1 -1
- package/dist/runtime/identity.js +16 -4
- package/dist/runtime/mcpi-runtime.js +7 -7
- package/dist/runtime/stdio.js +1 -1
- package/dist/runtime/transports/stdio/index.js +3 -3
- package/dist/runtime/utils/server.d.ts +9 -7
- package/dist/runtime/utils/server.js +44 -9
- package/dist/runtime/utils/tools.d.ts +5 -0
- package/dist/runtime/utils/tools.js +22 -1
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ class StdioTransport {
|
|
|
15
15
|
try {
|
|
16
16
|
this.mcpServer.connect(this.transport);
|
|
17
17
|
if (this.debug) {
|
|
18
|
-
console.
|
|
18
|
+
console.error("[STDIO] MCP Server running with STDIO transport");
|
|
19
19
|
}
|
|
20
20
|
this.setupShutdownHandlers();
|
|
21
21
|
}
|
|
@@ -29,7 +29,7 @@ class StdioTransport {
|
|
|
29
29
|
setupShutdownHandlers() {
|
|
30
30
|
const shutdownHandler = () => {
|
|
31
31
|
if (this.debug) {
|
|
32
|
-
console.
|
|
32
|
+
console.error("[STDIO] Shutting down STDIO transport");
|
|
33
33
|
}
|
|
34
34
|
process.exit(0);
|
|
35
35
|
};
|
|
@@ -38,7 +38,7 @@ class StdioTransport {
|
|
|
38
38
|
}
|
|
39
39
|
shutdown() {
|
|
40
40
|
if (this.debug) {
|
|
41
|
-
console.
|
|
41
|
+
console.error("[STDIO] Shutting down STDIO transport");
|
|
42
42
|
}
|
|
43
43
|
process.exit(0);
|
|
44
44
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
2
3
|
export type ToolFile = {
|
|
3
4
|
metadata: unknown;
|
|
4
5
|
schema: unknown;
|
|
5
6
|
default: (args: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
6
7
|
};
|
|
7
8
|
export declare const injectedTools: Record<string, () => Promise<ToolFile>>;
|
|
8
|
-
export declare const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly tools: {
|
|
13
|
-
readonly listChanged: true;
|
|
14
|
-
};
|
|
9
|
+
export declare const SERVER_INFO: Implementation;
|
|
10
|
+
export declare const SERVER_CAPABILITIES: {
|
|
11
|
+
capabilities: {
|
|
12
|
+
tools: {};
|
|
15
13
|
};
|
|
16
14
|
};
|
|
15
|
+
declare global {
|
|
16
|
+
var __MCPI_SERVER_INSTANCE__: McpServer | undefined;
|
|
17
|
+
var __MCPI_SERVER_CREATED__: boolean | undefined;
|
|
18
|
+
}
|
|
17
19
|
/** Loads tools and injects them into the server */
|
|
18
20
|
export declare function configureServer(server: McpServer, toolModules: Map<string, ToolFile>): Promise<McpServer>;
|
|
19
21
|
export declare function loadTools(): readonly [Promise<void>[], Map<string, ToolFile>];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SERVER_CAPABILITIES = exports.SERVER_INFO = exports.injectedTools = void 0;
|
|
4
4
|
exports.configureServer = configureServer;
|
|
5
5
|
exports.loadTools = loadTools;
|
|
6
6
|
exports.createServer = createServer;
|
|
@@ -14,16 +14,20 @@ const rawIdentityConfig = typeof IDENTITY_CONFIG !== "undefined" ? IDENTITY_CONF
|
|
|
14
14
|
const identityConfig = rawIdentityConfig
|
|
15
15
|
? JSON.parse(rawIdentityConfig)
|
|
16
16
|
: undefined;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Server info (first parameter to Server constructor)
|
|
18
|
+
exports.SERVER_INFO = {
|
|
19
19
|
name: "MCP Server",
|
|
20
20
|
version: "0.0.1",
|
|
21
|
+
};
|
|
22
|
+
// Server capabilities (second parameter to Server constructor)
|
|
23
|
+
exports.SERVER_CAPABILITIES = {
|
|
21
24
|
capabilities: {
|
|
22
|
-
tools: {
|
|
23
|
-
listChanged: true,
|
|
24
|
-
},
|
|
25
|
+
tools: {},
|
|
25
26
|
},
|
|
26
27
|
};
|
|
28
|
+
if (typeof global !== 'undefined') {
|
|
29
|
+
global.__MCPI_SERVER_CREATED__ = global.__MCPI_SERVER_CREATED__ || false;
|
|
30
|
+
}
|
|
27
31
|
/** Loads tools and injects them into the server */
|
|
28
32
|
async function configureServer(server, toolModules) {
|
|
29
33
|
await (0, tools_1.addToolsToServer)(server, toolModules, identityConfig);
|
|
@@ -32,14 +36,45 @@ async function configureServer(server, toolModules) {
|
|
|
32
36
|
}
|
|
33
37
|
function loadTools() {
|
|
34
38
|
const toolModules = new Map();
|
|
35
|
-
|
|
39
|
+
// Debug: log what tools are being injected
|
|
40
|
+
const toolPaths = Object.keys(exports.injectedTools);
|
|
41
|
+
console.error("[loadTools] Injected tool paths:", toolPaths);
|
|
42
|
+
const toolPromises = toolPaths.map((path) => exports.injectedTools[path]().then((toolModule) => {
|
|
43
|
+
console.error("[loadTools] Loaded tool from path:", path);
|
|
36
44
|
toolModules.set(path, toolModule);
|
|
37
45
|
}));
|
|
38
46
|
return [toolPromises, toolModules];
|
|
39
47
|
}
|
|
40
48
|
async function createServer() {
|
|
41
|
-
|
|
49
|
+
console.error("[createServer] Starting server creation");
|
|
50
|
+
// Guard against double initialization using global scope
|
|
51
|
+
// This ensures singleton even if webpack creates multiple module instances
|
|
52
|
+
if (typeof global !== 'undefined' && global.__MCPI_SERVER_CREATED__) {
|
|
53
|
+
console.error("[createServer] Server already exists, returning cached instance");
|
|
54
|
+
if (global.__MCPI_SERVER_INSTANCE__) {
|
|
55
|
+
return global.__MCPI_SERVER_INSTANCE__;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
console.error("[createServer] Creating new McpServer");
|
|
59
|
+
console.error("[createServer] SERVER_INFO constant:", JSON.stringify(exports.SERVER_INFO));
|
|
60
|
+
console.error("[createServer] SERVER_CAPABILITIES constant:", JSON.stringify(exports.SERVER_CAPABILITIES));
|
|
61
|
+
console.error("[createServer] Calling: new McpServer(SERVER_INFO, SERVER_CAPABILITIES)");
|
|
62
|
+
const server = new index_js_1.Server(exports.SERVER_INFO, exports.SERVER_CAPABILITIES);
|
|
63
|
+
console.error("[createServer] Server created successfully");
|
|
64
|
+
// Debug: Verify what the server actually received
|
|
65
|
+
const serverAny = server;
|
|
66
|
+
console.error("[createServer] Actual server._serverInfo:", JSON.stringify(serverAny._serverInfo || "undefined"));
|
|
67
|
+
console.error("[createServer] Actual server._capabilities:", JSON.stringify(serverAny._capabilities || "undefined"));
|
|
68
|
+
console.error("[createServer] Loading tools...");
|
|
42
69
|
const [toolPromises, toolModules] = loadTools();
|
|
43
70
|
await Promise.all(toolPromises);
|
|
44
|
-
|
|
71
|
+
console.error("[createServer] Tools loaded, configuring server");
|
|
72
|
+
const configuredServer = await configureServer(server, toolModules);
|
|
73
|
+
console.error("[createServer] Server configured successfully");
|
|
74
|
+
// Store in global scope
|
|
75
|
+
if (typeof global !== 'undefined') {
|
|
76
|
+
global.__MCPI_SERVER_CREATED__ = true;
|
|
77
|
+
global.__MCPI_SERVER_INSTANCE__ = configuredServer;
|
|
78
|
+
}
|
|
79
|
+
return configuredServer;
|
|
45
80
|
}
|
|
@@ -12,9 +12,14 @@ export type MCPICallToolResult = CallToolResult & {
|
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
declare global {
|
|
16
|
+
var __MCPI_HANDLERS_REGISTERED__: boolean | undefined;
|
|
17
|
+
}
|
|
15
18
|
/** Loads tools and injects them into the server */
|
|
16
19
|
export declare function addToolsToServer(server: McpServer, toolModules: Map<string, ToolFile>, identityConfig?: {
|
|
17
20
|
enabled: boolean;
|
|
18
21
|
debug?: boolean;
|
|
19
22
|
environment?: string;
|
|
23
|
+
devIdentityPath?: string;
|
|
24
|
+
privacyMode?: boolean;
|
|
20
25
|
}): Promise<McpServer>;
|
|
@@ -24,19 +24,36 @@ function pathToName(path) {
|
|
|
24
24
|
const fileName = path.split("/").pop() || path;
|
|
25
25
|
return fileName.replace(/\.[^/.]+$/, "");
|
|
26
26
|
}
|
|
27
|
+
if (typeof global !== 'undefined') {
|
|
28
|
+
global.__MCPI_HANDLERS_REGISTERED__ = global.__MCPI_HANDLERS_REGISTERED__ || false;
|
|
29
|
+
}
|
|
27
30
|
/** Loads tools and injects them into the server */
|
|
28
31
|
async function addToolsToServer(server, toolModules, identityConfig) {
|
|
32
|
+
// Guard against double registration using global scope
|
|
33
|
+
// Set this IMMEDIATELY to prevent race conditions
|
|
34
|
+
if (typeof global !== 'undefined') {
|
|
35
|
+
if (global.__MCPI_HANDLERS_REGISTERED__) {
|
|
36
|
+
console.error("[MCPI] Handlers already registered, skipping duplicate registration");
|
|
37
|
+
return server;
|
|
38
|
+
}
|
|
39
|
+
// Mark as registered RIGHT NOW before doing anything else
|
|
40
|
+
global.__MCPI_HANDLERS_REGISTERED__ = true;
|
|
41
|
+
}
|
|
42
|
+
console.error("[MCPI] Registering handlers for the first time");
|
|
29
43
|
// Initialize identity manager if identity is enabled
|
|
30
44
|
let identityManager = null;
|
|
31
45
|
if (identityConfig?.enabled) {
|
|
32
46
|
try {
|
|
33
47
|
identityManager = new identity_1.IdentityManager({
|
|
34
|
-
environment: identityConfig.environment ||
|
|
48
|
+
environment: identityConfig.environment ||
|
|
49
|
+
"development",
|
|
50
|
+
devIdentityPath: identityConfig.devIdentityPath,
|
|
35
51
|
});
|
|
36
52
|
// Ensure identity exists (loads or generates it)
|
|
37
53
|
const identity = await identityManager.ensureIdentity();
|
|
38
54
|
if (identityConfig.debug) {
|
|
39
55
|
console.error(`[MCPI] Identity enabled - DID: ${identity.did}`);
|
|
56
|
+
console.error(`[MCPI] Identity path: ${identityConfig.devIdentityPath || '.mcpi/identity.json'}`);
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
59
|
catch (error) {
|
|
@@ -87,6 +104,8 @@ async function addToolsToServer(server, toolModules, identityConfig) {
|
|
|
87
104
|
tools.push(tool);
|
|
88
105
|
toolHandlers.set(toolConfig.name, handler);
|
|
89
106
|
});
|
|
107
|
+
// Debug: log server state before registering handler
|
|
108
|
+
console.error("[MCPI] About to register tools/list handler");
|
|
90
109
|
// Register tools/list handler
|
|
91
110
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async (request) => {
|
|
92
111
|
return {
|
|
@@ -135,6 +154,7 @@ async function addToolsToServer(server, toolModules, identityConfig) {
|
|
|
135
154
|
};
|
|
136
155
|
// Create a session context for standalone tool calls
|
|
137
156
|
// In a full implementation, this would use proper handshake
|
|
157
|
+
// TODO: Use proper handshake
|
|
138
158
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
139
159
|
const session = {
|
|
140
160
|
sessionId: `tool-${Date.now()}`,
|
|
@@ -181,5 +201,6 @@ async function addToolsToServer(server, toolModules, identityConfig) {
|
|
|
181
201
|
};
|
|
182
202
|
}
|
|
183
203
|
});
|
|
204
|
+
console.error("[MCPI] Handlers registered successfully");
|
|
184
205
|
return server;
|
|
185
206
|
}
|