@kya-os/mcp-i 1.2.5 → 1.2.7

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.
@@ -8,6 +8,12 @@ const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
8
8
  const tools_1 = require("./tools");
9
9
  // @ts-expect-error: injected by compiler
10
10
  exports.injectedTools = INJECTED_TOOLS;
11
+ // Parse identity config from injected variable
12
+ // @ts-expect-error: injected by compiler
13
+ const rawIdentityConfig = typeof IDENTITY_CONFIG !== "undefined" ? IDENTITY_CONFIG : undefined;
14
+ const identityConfig = rawIdentityConfig
15
+ ? JSON.parse(rawIdentityConfig)
16
+ : undefined;
11
17
  exports.INJECTED_CONFIG = {
12
18
  // TODO get from project config
13
19
  name: "MCP Server",
@@ -20,7 +26,7 @@ exports.INJECTED_CONFIG = {
20
26
  };
21
27
  /** Loads tools and injects them into the server */
22
28
  async function configureServer(server, toolModules) {
23
- (0, tools_1.addToolsToServer)(server, toolModules);
29
+ await (0, tools_1.addToolsToServer)(server, toolModules, identityConfig);
24
30
  // TODO: implement addResourcesToServer, addPromptsToServer
25
31
  return server;
26
32
  }
@@ -1,8 +1,20 @@
1
1
  import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
2
2
  import { ZodTypeAny } from "zod";
3
3
  import { ToolFile } from "./server";
4
+ import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
+ import { DetachedProof } from "@kya-os/contracts/proof";
4
6
  export type ZodRawShape = {
5
7
  [k: string]: ZodTypeAny;
6
8
  };
9
+ export type MCPICallToolResult = CallToolResult & {
10
+ _meta?: {
11
+ proof?: DetachedProof;
12
+ [key: string]: unknown;
13
+ };
14
+ };
7
15
  /** Loads tools and injects them into the server */
8
- export declare function addToolsToServer(server: McpServer, toolModules: Map<string, ToolFile>): McpServer;
16
+ export declare function addToolsToServer(server: McpServer, toolModules: Map<string, ToolFile>, identityConfig?: {
17
+ enabled: boolean;
18
+ debug?: boolean;
19
+ environment?: string;
20
+ }): Promise<McpServer>;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addToolsToServer = addToolsToServer;
4
4
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
5
+ const proof_1 = require("../proof");
6
+ const identity_1 = require("../identity");
5
7
  /** Validates if a value is a valid Zod schema object */
6
8
  function isZodRawShape(value) {
7
9
  if (typeof value !== "object" || value === null) {
@@ -23,7 +25,25 @@ function pathToName(path) {
23
25
  return fileName.replace(/\.[^/.]+$/, "");
24
26
  }
25
27
  /** Loads tools and injects them into the server */
26
- function addToolsToServer(server, toolModules) {
28
+ async function addToolsToServer(server, toolModules, identityConfig) {
29
+ // Initialize identity manager if identity is enabled
30
+ let identityManager = null;
31
+ if (identityConfig?.enabled) {
32
+ try {
33
+ identityManager = new identity_1.IdentityManager({
34
+ environment: identityConfig.environment || "development",
35
+ });
36
+ // Ensure identity exists (loads or generates it)
37
+ const identity = await identityManager.ensureIdentity();
38
+ if (identityConfig.debug) {
39
+ console.error(`[MCPI] Identity enabled - DID: ${identity.did}`);
40
+ }
41
+ }
42
+ catch (error) {
43
+ console.error("[MCPI] Failed to initialize identity:", error);
44
+ // Continue without identity if initialization fails
45
+ }
46
+ }
27
47
  // Collect all tools and their handlers
28
48
  const tools = [];
29
49
  const toolHandlers = new Map();
@@ -89,8 +109,10 @@ function addToolsToServer(server, toolModules) {
89
109
  };
90
110
  }
91
111
  try {
112
+ // Execute the tool handler
92
113
  const result = await handler(args || {});
93
- return {
114
+ // Build base response
115
+ const baseResponse = {
94
116
  content: [
95
117
  {
96
118
  type: "text",
@@ -98,6 +120,54 @@ function addToolsToServer(server, toolModules) {
98
120
  },
99
121
  ],
100
122
  };
123
+ // If identity is enabled, generate cryptographic proof
124
+ if (identityManager) {
125
+ try {
126
+ // Ensure identity exists
127
+ const identity = await identityManager.ensureIdentity();
128
+ // Create a session context for this request
129
+ const toolRequest = {
130
+ method: name,
131
+ params: args || {},
132
+ };
133
+ const toolResponse = {
134
+ data: result,
135
+ };
136
+ // Create a session context for standalone tool calls
137
+ // In a full implementation, this would use proper handshake
138
+ const timestamp = Math.floor(Date.now() / 1000);
139
+ const session = {
140
+ sessionId: `tool-${Date.now()}`,
141
+ nonce: `${Date.now()}`,
142
+ audience: "client",
143
+ createdAt: timestamp,
144
+ timestamp,
145
+ lastActivity: timestamp,
146
+ ttlMinutes: 30,
147
+ };
148
+ // Generate proof using the proof generator
149
+ const proofGen = new proof_1.ProofGenerator(identity);
150
+ const proof = await proofGen.generateProof(toolRequest, toolResponse, session);
151
+ if (identityConfig?.debug) {
152
+ console.error(`[MCPI] Generated proof for tool "${name}" - DID: ${proof.meta.did}`);
153
+ }
154
+ // Return response with proof metadata
155
+ return {
156
+ ...baseResponse,
157
+ _meta: {
158
+ proof,
159
+ },
160
+ };
161
+ }
162
+ catch (proofError) {
163
+ if (identityConfig?.debug) {
164
+ console.error(`[MCPI] Failed to generate proof for tool "${name}":`, proofError);
165
+ }
166
+ // Return base response without proof if generation fails
167
+ return baseResponse;
168
+ }
169
+ }
170
+ return baseResponse;
101
171
  }
102
172
  catch (error) {
103
173
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "The TypeScript MCP framework with identity features built-in",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -79,6 +79,9 @@
79
79
  "webpack-node-externals": "^3.0.0",
80
80
  "webpack-virtual-modules": "^0.5.0"
81
81
  },
82
+ "optionalDependencies": {
83
+ "@modelcontextprotocol/inspector": "^0.16.6"
84
+ },
82
85
  "devDependencies": {
83
86
  "@aws-sdk/client-dynamodb": "^3.0.0",
84
87
  "@types/content-type": "^1.1.9",