@elliotding/ai-agent-mcp 0.2.21 → 0.2.23
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/api/client.d.ts +4 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +7 -1
- package/dist/api/client.js.map +1 -1
- package/dist/client-adapters/codex-adapter.d.ts +49 -0
- package/dist/client-adapters/codex-adapter.d.ts.map +1 -0
- package/dist/client-adapters/codex-adapter.js +72 -0
- package/dist/client-adapters/codex-adapter.js.map +1 -0
- package/dist/client-adapters/cursor-adapter.d.ts +37 -0
- package/dist/client-adapters/cursor-adapter.d.ts.map +1 -0
- package/dist/client-adapters/cursor-adapter.js +68 -0
- package/dist/client-adapters/cursor-adapter.js.map +1 -0
- package/dist/client-adapters/index.d.ts +91 -0
- package/dist/client-adapters/index.d.ts.map +1 -0
- package/dist/client-adapters/index.js +49 -0
- package/dist/client-adapters/index.js.map +1 -0
- package/dist/config/index.d.ts +19 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +12 -2
- package/dist/config/index.js.map +1 -1
- package/dist/prompts/manager.d.ts +73 -0
- package/dist/prompts/manager.d.ts.map +1 -1
- package/dist/prompts/manager.js +243 -7
- package/dist/prompts/manager.js.map +1 -1
- package/dist/server/http.d.ts +10 -6
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +130 -89
- package/dist/server/http.js.map +1 -1
- package/dist/server/streamable-http.d.ts +28 -0
- package/dist/server/streamable-http.d.ts.map +1 -0
- package/dist/server/streamable-http.js +147 -0
- package/dist/server/streamable-http.js.map +1 -0
- package/dist/server.d.ts +8 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +60 -96
- package/dist/server.js.map +1 -1
- package/dist/telemetry/manager.d.ts +5 -0
- package/dist/telemetry/manager.d.ts.map +1 -1
- package/dist/telemetry/manager.js +5 -0
- package/dist/telemetry/manager.js.map +1 -1
- package/dist/tools/manage-subscription.d.ts.map +1 -1
- package/dist/tools/manage-subscription.js +162 -20
- package/dist/tools/manage-subscription.js.map +1 -1
- package/dist/tools/policy-generator.d.ts +31 -0
- package/dist/tools/policy-generator.d.ts.map +1 -0
- package/dist/tools/policy-generator.js +53 -0
- package/dist/tools/policy-generator.js.map +1 -0
- package/dist/tools/query-usage-stats.d.ts +8 -0
- package/dist/tools/query-usage-stats.d.ts.map +1 -1
- package/dist/tools/query-usage-stats.js +26 -1
- package/dist/tools/query-usage-stats.js.map +1 -1
- package/dist/tools/resolve-prompt-content.d.ts.map +1 -1
- package/dist/tools/resolve-prompt-content.js +39 -1
- package/dist/tools/resolve-prompt-content.js.map +1 -1
- package/dist/tools/search-resources.d.ts +5 -0
- package/dist/tools/search-resources.d.ts.map +1 -1
- package/dist/tools/search-resources.js +73 -7
- package/dist/tools/search-resources.js.map +1 -1
- package/dist/tools/sync-resources.d.ts.map +1 -1
- package/dist/tools/sync-resources.js +284 -99
- package/dist/tools/sync-resources.js.map +1 -1
- package/dist/tools/uninstall-resource.d.ts.map +1 -1
- package/dist/tools/uninstall-resource.js +100 -12
- package/dist/tools/uninstall-resource.js.map +1 -1
- package/dist/types/tools.d.ts +128 -1
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/codex-paths.d.ts +39 -0
- package/dist/utils/codex-paths.d.ts.map +1 -0
- package/dist/utils/codex-paths.js +56 -0
- package/dist/utils/codex-paths.js.map +1 -0
- package/package.json +1 -1
- package/dist/transport/sse.d.ts +0 -29
- package/dist/transport/sse.d.ts.map +0 -1
- package/dist/transport/sse.js +0 -271
- package/dist/transport/sse.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex client directory path resolver.
|
|
3
|
+
*
|
|
4
|
+
* Returns tilde-based portable paths suitable for use in LocalAction
|
|
5
|
+
* instructions that the AI Agent will execute on the user's local machine.
|
|
6
|
+
*
|
|
7
|
+
* Directory layout:
|
|
8
|
+
* ~/.csp-ai-agent/codex/ – Codex-specific cached resources (sibling of .cursor)
|
|
9
|
+
* skills/<name>/ – Complex Codex skills
|
|
10
|
+
* csp-routing-policy.md – Aggregated routing policy injected into Codex
|
|
11
|
+
* ~/.codex/ – Codex native config directory
|
|
12
|
+
* config.toml – Codex configuration (developer_instructions lives here)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Returns the root directory for Codex-specific CSP agent resources
|
|
16
|
+
* as a client-side portable path.
|
|
17
|
+
*
|
|
18
|
+
* The AI Agent must expand `~` to the user's home directory.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCodexRootDirForClient(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the directory where complex Codex skills are cached.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getCodexSkillDirForClient(skillName: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the directory where Codex complex-skill manifests are cached.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getCodexManifestDirForClient(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the path of the aggregated CSP routing policy markdown file
|
|
31
|
+
* that is injected into Codex via `developer_instructions`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getCodexPolicyPathForClient(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the path to the Codex native configuration file.
|
|
36
|
+
* This is where `developer_instructions` (and other runtime options) live.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getCodexConfigTomlPathForClient(): string;
|
|
39
|
+
//# sourceMappingURL=codex-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-paths.d.ts","sourceRoot":"","sources":["../../src/utils/codex-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAErD;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,CAExD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Codex client directory path resolver.
|
|
4
|
+
*
|
|
5
|
+
* Returns tilde-based portable paths suitable for use in LocalAction
|
|
6
|
+
* instructions that the AI Agent will execute on the user's local machine.
|
|
7
|
+
*
|
|
8
|
+
* Directory layout:
|
|
9
|
+
* ~/.csp-ai-agent/codex/ – Codex-specific cached resources (sibling of .cursor)
|
|
10
|
+
* skills/<name>/ – Complex Codex skills
|
|
11
|
+
* csp-routing-policy.md – Aggregated routing policy injected into Codex
|
|
12
|
+
* ~/.codex/ – Codex native config directory
|
|
13
|
+
* config.toml – Codex configuration (developer_instructions lives here)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.getCodexRootDirForClient = getCodexRootDirForClient;
|
|
17
|
+
exports.getCodexSkillDirForClient = getCodexSkillDirForClient;
|
|
18
|
+
exports.getCodexManifestDirForClient = getCodexManifestDirForClient;
|
|
19
|
+
exports.getCodexPolicyPathForClient = getCodexPolicyPathForClient;
|
|
20
|
+
exports.getCodexConfigTomlPathForClient = getCodexConfigTomlPathForClient;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the root directory for Codex-specific CSP agent resources
|
|
23
|
+
* as a client-side portable path.
|
|
24
|
+
*
|
|
25
|
+
* The AI Agent must expand `~` to the user's home directory.
|
|
26
|
+
*/
|
|
27
|
+
function getCodexRootDirForClient() {
|
|
28
|
+
return '~/.csp-ai-agent/codex';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the directory where complex Codex skills are cached.
|
|
32
|
+
*/
|
|
33
|
+
function getCodexSkillDirForClient(skillName) {
|
|
34
|
+
return `${getCodexRootDirForClient()}/skills/${skillName}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the directory where Codex complex-skill manifests are cached.
|
|
38
|
+
*/
|
|
39
|
+
function getCodexManifestDirForClient() {
|
|
40
|
+
return `${getCodexRootDirForClient()}/.manifests`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the path of the aggregated CSP routing policy markdown file
|
|
44
|
+
* that is injected into Codex via `developer_instructions`.
|
|
45
|
+
*/
|
|
46
|
+
function getCodexPolicyPathForClient() {
|
|
47
|
+
return `${getCodexRootDirForClient()}/csp-routing-policy.md`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the path to the Codex native configuration file.
|
|
51
|
+
* This is where `developer_instructions` (and other runtime options) live.
|
|
52
|
+
*/
|
|
53
|
+
function getCodexConfigTomlPathForClient() {
|
|
54
|
+
return '~/.codex/config.toml';
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=codex-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-paths.js","sourceRoot":"","sources":["../../src/utils/codex-paths.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAQH,4DAEC;AAKD,8DAEC;AAKD,oEAEC;AAMD,kEAEC;AAMD,0EAEC;AAtCD;;;;;GAKG;AACH,SAAgB,wBAAwB;IACtC,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,SAAiB;IACzD,OAAO,GAAG,wBAAwB,EAAE,WAAW,SAAS,EAAE,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,SAAgB,4BAA4B;IAC1C,OAAO,GAAG,wBAAwB,EAAE,aAAa,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,SAAgB,2BAA2B;IACzC,OAAO,GAAG,wBAAwB,EAAE,wBAAwB,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,SAAgB,+BAA+B;IAC7C,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
package/dist/transport/sse.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSE Transport Implementation
|
|
3
|
-
* MCP protocol over Server-Sent Events
|
|
4
|
-
*/
|
|
5
|
-
export interface SSEMessage {
|
|
6
|
-
jsonrpc: '2.0';
|
|
7
|
-
id?: string | number;
|
|
8
|
-
method?: string;
|
|
9
|
-
params?: unknown;
|
|
10
|
-
result?: unknown;
|
|
11
|
-
error?: {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
data?: unknown;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export declare class SSETransport {
|
|
18
|
-
constructor();
|
|
19
|
-
/**
|
|
20
|
-
* Handle incoming message from client
|
|
21
|
-
*/
|
|
22
|
-
handleMessage(sessionId: string, message: SSEMessage): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Send message to client via SSE
|
|
25
|
-
*/
|
|
26
|
-
private sendMessage;
|
|
27
|
-
}
|
|
28
|
-
export declare const sseTransport: SSETransport;
|
|
29
|
-
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/transport/sse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,CAAC;CACH;AAED,qBAAa,YAAY;;IAKvB;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAwQ1E;;OAEG;IACH,OAAO,CAAC,WAAW;CAMpB;AAGD,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
package/dist/transport/sse.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SSE Transport Implementation
|
|
4
|
-
* MCP protocol over Server-Sent Events
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.sseTransport = exports.SSETransport = void 0;
|
|
8
|
-
const logger_1 = require("../utils/logger");
|
|
9
|
-
const manager_1 = require("../session/manager");
|
|
10
|
-
const registry_1 = require("../tools/registry");
|
|
11
|
-
const middleware_1 = require("../auth/middleware");
|
|
12
|
-
class SSETransport {
|
|
13
|
-
constructor() {
|
|
14
|
-
logger_1.logger.info('SSE transport initialized');
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Handle incoming message from client
|
|
18
|
-
*/
|
|
19
|
-
async handleMessage(sessionId, message) {
|
|
20
|
-
const messageStartTime = Date.now();
|
|
21
|
-
logger_1.logger.info({
|
|
22
|
-
type: 'sse_message_received',
|
|
23
|
-
sessionId,
|
|
24
|
-
method: message.method,
|
|
25
|
-
messageId: message.id,
|
|
26
|
-
hasParams: !!message.params,
|
|
27
|
-
timestamp: new Date().toISOString()
|
|
28
|
-
}, `SSE message received: ${message.method}`);
|
|
29
|
-
try {
|
|
30
|
-
// Validate session
|
|
31
|
-
(0, logger_1.logToolStep)('sse', 'Validating session', { sessionId });
|
|
32
|
-
const session = manager_1.sessionManager.getSession(sessionId);
|
|
33
|
-
if (!session) {
|
|
34
|
-
logger_1.logger.error({
|
|
35
|
-
type: 'sse_error',
|
|
36
|
-
sessionId,
|
|
37
|
-
method: message.method,
|
|
38
|
-
error: 'session_not_found',
|
|
39
|
-
timestamp: new Date().toISOString()
|
|
40
|
-
}, 'Session not found or expired');
|
|
41
|
-
throw new Error('Session not found or expired');
|
|
42
|
-
}
|
|
43
|
-
logger_1.logger.debug({
|
|
44
|
-
type: 'sse_session_validated',
|
|
45
|
-
sessionId,
|
|
46
|
-
userId: session.userId,
|
|
47
|
-
email: session.email,
|
|
48
|
-
groups: session.groups,
|
|
49
|
-
timestamp: new Date().toISOString()
|
|
50
|
-
}, 'Session validated');
|
|
51
|
-
// Update session activity
|
|
52
|
-
manager_1.sessionManager.updateActivity(sessionId);
|
|
53
|
-
(0, logger_1.logToolStep)('sse', 'Session activity updated', { sessionId });
|
|
54
|
-
// Handle MCP message
|
|
55
|
-
if (message.method === 'tools/list') {
|
|
56
|
-
(0, logger_1.logToolStep)('sse', 'Handling tools/list request', { sessionId });
|
|
57
|
-
const tools = registry_1.toolRegistry.getMCPToolDefinitions();
|
|
58
|
-
logger_1.logger.info({
|
|
59
|
-
type: 'sse_tools_list',
|
|
60
|
-
sessionId,
|
|
61
|
-
toolCount: tools.length,
|
|
62
|
-
toolNames: tools.map(t => t.name),
|
|
63
|
-
timestamp: new Date().toISOString()
|
|
64
|
-
}, `Returning ${tools.length} tool definitions`);
|
|
65
|
-
const response = {
|
|
66
|
-
jsonrpc: '2.0',
|
|
67
|
-
id: message.id,
|
|
68
|
-
result: { tools },
|
|
69
|
-
};
|
|
70
|
-
this.sendMessage(sessionId, response);
|
|
71
|
-
}
|
|
72
|
-
else if (message.method === 'tools/call') {
|
|
73
|
-
const params = message.params;
|
|
74
|
-
const toolName = params.name;
|
|
75
|
-
const args = params.arguments || {};
|
|
76
|
-
logger_1.logger.info({
|
|
77
|
-
type: 'sse_tool_call',
|
|
78
|
-
sessionId,
|
|
79
|
-
toolName,
|
|
80
|
-
userId: session.userId,
|
|
81
|
-
email: session.email,
|
|
82
|
-
argsPreview: JSON.stringify(args).substring(0, 200),
|
|
83
|
-
timestamp: new Date().toISOString()
|
|
84
|
-
}, `Executing tool: ${toolName}`);
|
|
85
|
-
(0, logger_1.logToolStep)(toolName, 'Tool call initiated via SSE', {
|
|
86
|
-
sessionId,
|
|
87
|
-
userId: session.userId,
|
|
88
|
-
email: session.email
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
// Check permissions if user is authenticated
|
|
92
|
-
if (session.userId && session.groups && session.groups.length > 0) {
|
|
93
|
-
(0, logger_1.logToolStep)(toolName, 'Checking tool permissions', {
|
|
94
|
-
userId: session.userId,
|
|
95
|
-
email: session.email,
|
|
96
|
-
groups: session.groups
|
|
97
|
-
});
|
|
98
|
-
const permissionStartTime = Date.now();
|
|
99
|
-
const permissionCheck = (0, middleware_1.checkToolCallPermission)(toolName, {
|
|
100
|
-
userId: session.userId,
|
|
101
|
-
email: session.email,
|
|
102
|
-
groups: session.groups,
|
|
103
|
-
});
|
|
104
|
-
const permissionDuration = Date.now() - permissionStartTime;
|
|
105
|
-
if (!permissionCheck.allowed) {
|
|
106
|
-
logger_1.logger.warn({
|
|
107
|
-
type: 'sse_permission_denied',
|
|
108
|
-
sessionId,
|
|
109
|
-
userId: session.userId,
|
|
110
|
-
email: session.email,
|
|
111
|
-
groups: session.groups,
|
|
112
|
-
toolName,
|
|
113
|
-
reason: permissionCheck.reason,
|
|
114
|
-
duration: permissionDuration,
|
|
115
|
-
timestamp: new Date().toISOString()
|
|
116
|
-
}, `Tool call permission denied for ${toolName}`);
|
|
117
|
-
const errorResponse = {
|
|
118
|
-
jsonrpc: '2.0',
|
|
119
|
-
id: message.id,
|
|
120
|
-
error: {
|
|
121
|
-
code: -32600, // Invalid Request
|
|
122
|
-
message: permissionCheck.reason || 'Permission denied',
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
this.sendMessage(sessionId, errorResponse);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
logger_1.logger.debug({
|
|
129
|
-
type: 'sse_permission_granted',
|
|
130
|
-
sessionId,
|
|
131
|
-
userId: session.userId,
|
|
132
|
-
toolName,
|
|
133
|
-
duration: permissionDuration,
|
|
134
|
-
timestamp: new Date().toISOString()
|
|
135
|
-
}, `Permission granted for ${toolName}`);
|
|
136
|
-
}
|
|
137
|
-
(0, logger_1.logToolStep)(toolName, 'Executing tool handler', { args });
|
|
138
|
-
const toolStartTime = Date.now();
|
|
139
|
-
const result = await registry_1.toolRegistry.callTool(toolName, args);
|
|
140
|
-
const toolDuration = Date.now() - toolStartTime;
|
|
141
|
-
// Log complete result
|
|
142
|
-
logger_1.logger.info({
|
|
143
|
-
type: 'sse_tool_success',
|
|
144
|
-
sessionId,
|
|
145
|
-
toolName,
|
|
146
|
-
userId: session.userId,
|
|
147
|
-
resultType: typeof result,
|
|
148
|
-
resultPreview: JSON.stringify(result).substring(0, 500),
|
|
149
|
-
duration: toolDuration,
|
|
150
|
-
timestamp: new Date().toISOString()
|
|
151
|
-
}, `Tool ${toolName} executed successfully`);
|
|
152
|
-
(0, logger_1.logToolStep)(toolName, 'Tool execution completed', {
|
|
153
|
-
duration: toolDuration,
|
|
154
|
-
resultSize: JSON.stringify(result).length
|
|
155
|
-
});
|
|
156
|
-
const response = {
|
|
157
|
-
jsonrpc: '2.0',
|
|
158
|
-
id: message.id,
|
|
159
|
-
result,
|
|
160
|
-
};
|
|
161
|
-
this.sendMessage(sessionId, response);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
const toolDuration = Date.now() - messageStartTime;
|
|
165
|
-
logger_1.logger.error({
|
|
166
|
-
type: 'sse_tool_error',
|
|
167
|
-
sessionId,
|
|
168
|
-
toolName,
|
|
169
|
-
userId: session.userId,
|
|
170
|
-
error: error instanceof Error ? {
|
|
171
|
-
message: error.message,
|
|
172
|
-
stack: error.stack,
|
|
173
|
-
name: error.name
|
|
174
|
-
} : String(error),
|
|
175
|
-
duration: toolDuration,
|
|
176
|
-
timestamp: new Date().toISOString()
|
|
177
|
-
}, `Tool ${toolName} execution failed`);
|
|
178
|
-
const errorResponse = {
|
|
179
|
-
jsonrpc: '2.0',
|
|
180
|
-
id: message.id,
|
|
181
|
-
error: {
|
|
182
|
-
code: -32603,
|
|
183
|
-
message: error instanceof Error ? error.message : 'Tool execution failed',
|
|
184
|
-
data: error,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
this.sendMessage(sessionId, errorResponse);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else if (message.method === 'initialize') {
|
|
191
|
-
logger_1.logger.info({
|
|
192
|
-
type: 'sse_initialize',
|
|
193
|
-
sessionId,
|
|
194
|
-
timestamp: new Date().toISOString()
|
|
195
|
-
}, 'Client initialization request');
|
|
196
|
-
const response = {
|
|
197
|
-
jsonrpc: '2.0',
|
|
198
|
-
id: message.id,
|
|
199
|
-
result: {
|
|
200
|
-
protocolVersion: '2024-11-05',
|
|
201
|
-
capabilities: {
|
|
202
|
-
tools: {},
|
|
203
|
-
},
|
|
204
|
-
serverInfo: {
|
|
205
|
-
name: 'csp-ai-agent-mcp',
|
|
206
|
-
version: '0.2.0',
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
this.sendMessage(sessionId, response);
|
|
211
|
-
}
|
|
212
|
-
else if (message.method === 'ping') {
|
|
213
|
-
// Keepalive ping
|
|
214
|
-
logger_1.logger.debug({
|
|
215
|
-
type: 'sse_ping',
|
|
216
|
-
sessionId,
|
|
217
|
-
timestamp: new Date().toISOString()
|
|
218
|
-
}, 'Keepalive ping received');
|
|
219
|
-
const response = {
|
|
220
|
-
jsonrpc: '2.0',
|
|
221
|
-
id: message.id,
|
|
222
|
-
result: { type: 'pong' },
|
|
223
|
-
};
|
|
224
|
-
this.sendMessage(sessionId, response);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
// Unknown method
|
|
228
|
-
logger_1.logger.warn({
|
|
229
|
-
type: 'sse_unknown_method',
|
|
230
|
-
sessionId,
|
|
231
|
-
method: message.method,
|
|
232
|
-
timestamp: new Date().toISOString()
|
|
233
|
-
}, `Unknown method: ${message.method}`);
|
|
234
|
-
const errorResponse = {
|
|
235
|
-
jsonrpc: '2.0',
|
|
236
|
-
id: message.id,
|
|
237
|
-
error: {
|
|
238
|
-
code: -32601,
|
|
239
|
-
message: `Method not found: ${message.method}`,
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
this.sendMessage(sessionId, errorResponse);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
logger_1.logger.error({ error, sessionId }, 'Error handling message');
|
|
247
|
-
const errorResponse = {
|
|
248
|
-
jsonrpc: '2.0',
|
|
249
|
-
id: message.id,
|
|
250
|
-
error: {
|
|
251
|
-
code: -32603,
|
|
252
|
-
message: error instanceof Error ? error.message : 'Internal error',
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
this.sendMessage(sessionId, errorResponse);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Send message to client via SSE
|
|
260
|
-
*/
|
|
261
|
-
sendMessage(sessionId, message) {
|
|
262
|
-
const sent = manager_1.sessionManager.sendMessage(sessionId, message);
|
|
263
|
-
if (!sent) {
|
|
264
|
-
logger_1.logger.warn({ sessionId, messageId: message.id }, 'Failed to send message to client');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
exports.SSETransport = SSETransport;
|
|
269
|
-
// Singleton instance
|
|
270
|
-
exports.sseTransport = new SSETransport();
|
|
271
|
-
//# sourceMappingURL=sse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/transport/sse.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAsD;AACtD,gDAAoD;AACpD,gDAAiD;AACjD,mDAA6D;AAe7D,MAAa,YAAY;IACvB;QACE,eAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CA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