@defai.digital/mcp-server 13.0.3
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 +214 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/bootstrap.d.ts +89 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +161 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +136 -0
- package/dist/middleware/rate-limiter.d.ts.map +1 -0
- package/dist/middleware/rate-limiter.js +262 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/prompts/agent-guide.d.ts +16 -0
- package/dist/prompts/agent-guide.d.ts.map +1 -0
- package/dist/prompts/agent-guide.js +391 -0
- package/dist/prompts/agent-guide.js.map +1 -0
- package/dist/prompts/explain-workflow.d.ts +15 -0
- package/dist/prompts/explain-workflow.d.ts.map +1 -0
- package/dist/prompts/explain-workflow.js +157 -0
- package/dist/prompts/explain-workflow.js.map +1 -0
- package/dist/prompts/index.d.ts +39 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +83 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/review-changes.d.ts +15 -0
- package/dist/prompts/review-changes.d.ts.map +1 -0
- package/dist/prompts/review-changes.js +102 -0
- package/dist/prompts/review-changes.js.map +1 -0
- package/dist/prompts/troubleshoot-session.d.ts +15 -0
- package/dist/prompts/troubleshoot-session.d.ts.map +1 -0
- package/dist/prompts/troubleshoot-session.js +156 -0
- package/dist/prompts/troubleshoot-session.js.map +1 -0
- package/dist/registry-accessor.d.ts +83 -0
- package/dist/registry-accessor.d.ts.map +1 -0
- package/dist/registry-accessor.js +153 -0
- package/dist/registry-accessor.js.map +1 -0
- package/dist/resources/agents.d.ts +40 -0
- package/dist/resources/agents.d.ts.map +1 -0
- package/dist/resources/agents.js +123 -0
- package/dist/resources/agents.js.map +1 -0
- package/dist/resources/config.d.ts +57 -0
- package/dist/resources/config.d.ts.map +1 -0
- package/dist/resources/config.js +222 -0
- package/dist/resources/config.js.map +1 -0
- package/dist/resources/index.d.ts +38 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +132 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/policies.d.ts +40 -0
- package/dist/resources/policies.d.ts.map +1 -0
- package/dist/resources/policies.js +122 -0
- package/dist/resources/policies.js.map +1 -0
- package/dist/resources/sessions.d.ts +30 -0
- package/dist/resources/sessions.d.ts.map +1 -0
- package/dist/resources/sessions.js +64 -0
- package/dist/resources/sessions.js.map +1 -0
- package/dist/resources/workflows.d.ts +40 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +143 -0
- package/dist/resources/workflows.js.map +1 -0
- package/dist/schema-registry.d.ts +23 -0
- package/dist/schema-registry.d.ts.map +1 -0
- package/dist/schema-registry.js +225 -0
- package/dist/schema-registry.js.map +1 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +393 -0
- package/dist/server.js.map +1 -0
- package/dist/session-accessor.d.ts +23 -0
- package/dist/session-accessor.d.ts.map +1 -0
- package/dist/session-accessor.js +39 -0
- package/dist/session-accessor.js.map +1 -0
- package/dist/shared-registry.d.ts +23 -0
- package/dist/shared-registry.d.ts.map +1 -0
- package/dist/shared-registry.js +235 -0
- package/dist/shared-registry.js.map +1 -0
- package/dist/stdio.d.ts +6 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +152 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tool-namespacing.d.ts +28 -0
- package/dist/tool-namespacing.d.ts.map +1 -0
- package/dist/tool-namespacing.js +80 -0
- package/dist/tool-namespacing.js.map +1 -0
- package/dist/tools/ability.d.ts +55 -0
- package/dist/tools/ability.d.ts.map +1 -0
- package/dist/tools/ability.js +560 -0
- package/dist/tools/ability.js.map +1 -0
- package/dist/tools/agent.d.ts +73 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +895 -0
- package/dist/tools/agent.js.map +1 -0
- package/dist/tools/config.d.ts +36 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +265 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/design.d.ts +42 -0
- package/dist/tools/design.d.ts.map +1 -0
- package/dist/tools/design.js +736 -0
- package/dist/tools/design.js.map +1 -0
- package/dist/tools/discuss.d.ts +40 -0
- package/dist/tools/discuss.d.ts.map +1 -0
- package/dist/tools/discuss.js +331 -0
- package/dist/tools/discuss.js.map +1 -0
- package/dist/tools/file-system.d.ts +63 -0
- package/dist/tools/file-system.d.ts.map +1 -0
- package/dist/tools/file-system.js +513 -0
- package/dist/tools/file-system.js.map +1 -0
- package/dist/tools/guard.d.ts +29 -0
- package/dist/tools/guard.d.ts.map +1 -0
- package/dist/tools/guard.js +311 -0
- package/dist/tools/guard.js.map +1 -0
- package/dist/tools/index.d.ts +35 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +178 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory.d.ts +101 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +704 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/orchestration.d.ts +58 -0
- package/dist/tools/orchestration.d.ts.map +1 -0
- package/dist/tools/orchestration.js +714 -0
- package/dist/tools/orchestration.js.map +1 -0
- package/dist/tools/review.d.ts +40 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +319 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/scaffold.d.ts +27 -0
- package/dist/tools/scaffold.d.ts.map +1 -0
- package/dist/tools/scaffold.js +495 -0
- package/dist/tools/scaffold.js.map +1 -0
- package/dist/tools/session.d.ts +75 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +749 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/telemetry.d.ts +58 -0
- package/dist/tools/telemetry.d.ts.map +1 -0
- package/dist/tools/telemetry.js +638 -0
- package/dist/tools/telemetry.js.map +1 -0
- package/dist/tools/trace.d.ts +29 -0
- package/dist/tools/trace.d.ts.map +1 -0
- package/dist/tools/trace.js +191 -0
- package/dist/tools/trace.js.map +1 -0
- package/dist/tools/workflow.d.ts +26 -0
- package/dist/tools/workflow.d.ts.map +1 -0
- package/dist/tools/workflow.js +269 -0
- package/dist/tools/workflow.js.map +1 -0
- package/dist/trace-wrapper.d.ts +79 -0
- package/dist/trace-wrapper.d.ts.map +1 -0
- package/dist/trace-wrapper.js +151 -0
- package/dist/trace-wrapper.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/artifact-store.d.ts +49 -0
- package/dist/utils/artifact-store.d.ts.map +1 -0
- package/dist/utils/artifact-store.js +102 -0
- package/dist/utils/artifact-store.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/response.d.ts +139 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +293 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/validation.d.ts +223 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +372 -0
- package/dist/validation.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Trace Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps tool handlers with tracing for observability.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-MCP-007: Every tool call produces exactly one trace
|
|
8
|
+
* - INV-MCP-008: Trace includes input/output/duration/success
|
|
9
|
+
*/
|
|
10
|
+
import { createToolTraceEvent } from '@defai.digital/contracts';
|
|
11
|
+
/**
|
|
12
|
+
* In-memory trace collector implementation
|
|
13
|
+
*/
|
|
14
|
+
export class InMemoryTraceCollector {
|
|
15
|
+
events = [];
|
|
16
|
+
maxEvents;
|
|
17
|
+
constructor(maxEvents = 1000) {
|
|
18
|
+
this.maxEvents = maxEvents;
|
|
19
|
+
}
|
|
20
|
+
record(event) {
|
|
21
|
+
this.events.push(event);
|
|
22
|
+
// Trim old events if over limit
|
|
23
|
+
if (this.events.length > this.maxEvents) {
|
|
24
|
+
this.events = this.events.slice(-this.maxEvents);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
getEvents() {
|
|
28
|
+
return [...this.events];
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
this.events = [];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gets summary statistics
|
|
35
|
+
*/
|
|
36
|
+
getSummary() {
|
|
37
|
+
const byTool = {};
|
|
38
|
+
let totalDuration = 0;
|
|
39
|
+
let successCount = 0;
|
|
40
|
+
for (const event of this.events) {
|
|
41
|
+
byTool[event.toolName] = (byTool[event.toolName] ?? 0) + 1;
|
|
42
|
+
totalDuration += event.durationMs;
|
|
43
|
+
if (event.success) {
|
|
44
|
+
successCount++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
totalInvocations: this.events.length,
|
|
49
|
+
successCount,
|
|
50
|
+
failureCount: this.events.length - successCount,
|
|
51
|
+
avgDurationMs: this.events.length > 0 ? totalDuration / this.events.length : 0,
|
|
52
|
+
byTool,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// Global Trace Collector
|
|
58
|
+
// ============================================================================
|
|
59
|
+
/**
|
|
60
|
+
* Global trace collector instance
|
|
61
|
+
*/
|
|
62
|
+
let globalCollector;
|
|
63
|
+
/**
|
|
64
|
+
* Sets the global trace collector
|
|
65
|
+
*/
|
|
66
|
+
export function setTraceCollector(collector) {
|
|
67
|
+
globalCollector = collector;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the global trace collector
|
|
71
|
+
*/
|
|
72
|
+
export function getTraceCollector() {
|
|
73
|
+
return globalCollector;
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Trace Wrapper Functions
|
|
77
|
+
// ============================================================================
|
|
78
|
+
/**
|
|
79
|
+
* Wraps a single tool handler with tracing
|
|
80
|
+
*
|
|
81
|
+
* INV-MCP-007: Every tool call produces exactly one trace event
|
|
82
|
+
* INV-MCP-008: Trace includes input/output/duration/success
|
|
83
|
+
*/
|
|
84
|
+
export function withTracing(toolName, handler, collector) {
|
|
85
|
+
return async (args) => {
|
|
86
|
+
const startTime = Date.now();
|
|
87
|
+
const effectiveCollector = collector ?? globalCollector;
|
|
88
|
+
try {
|
|
89
|
+
// Execute the handler
|
|
90
|
+
const result = await handler(args);
|
|
91
|
+
const durationMs = Date.now() - startTime;
|
|
92
|
+
// INV-MCP-007: Record trace event
|
|
93
|
+
if (effectiveCollector !== undefined) {
|
|
94
|
+
const firstContent = result.content.length > 0 ? result.content[0] : undefined;
|
|
95
|
+
const traceEvent = createToolTraceEvent(toolName, args, durationMs, !result.isError, {
|
|
96
|
+
output: firstContent?.text,
|
|
97
|
+
});
|
|
98
|
+
effectiveCollector.record(traceEvent);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const durationMs = Date.now() - startTime;
|
|
104
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
105
|
+
// INV-MCP-007: Record trace event even on error
|
|
106
|
+
if (effectiveCollector !== undefined) {
|
|
107
|
+
const traceEvent = createToolTraceEvent(toolName, args, durationMs, false, {
|
|
108
|
+
errorCode: 'TOOL_ERROR',
|
|
109
|
+
errorMessage: message,
|
|
110
|
+
});
|
|
111
|
+
effectiveCollector.record(traceEvent);
|
|
112
|
+
}
|
|
113
|
+
// Re-throw to let the server handle it
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wraps all handlers in a registry with tracing
|
|
120
|
+
*/
|
|
121
|
+
export function wrapHandlersWithTracing(handlers, collector) {
|
|
122
|
+
const wrapped = {};
|
|
123
|
+
for (const [name, handler] of Object.entries(handlers)) {
|
|
124
|
+
wrapped[name] = withTracing(name, handler, collector);
|
|
125
|
+
}
|
|
126
|
+
return wrapped;
|
|
127
|
+
}
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// Default Initialization
|
|
130
|
+
// ============================================================================
|
|
131
|
+
/**
|
|
132
|
+
* Initializes default trace collector if not already set
|
|
133
|
+
* Returns the collector, which may be InMemoryTraceCollector or a custom implementation
|
|
134
|
+
*/
|
|
135
|
+
export function initializeDefaultTracing() {
|
|
136
|
+
if (globalCollector === undefined) {
|
|
137
|
+
globalCollector = new InMemoryTraceCollector();
|
|
138
|
+
}
|
|
139
|
+
return globalCollector;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Gets the trace collector as InMemoryTraceCollector if it is one
|
|
143
|
+
* Returns undefined if no collector is set or if it's a different implementation
|
|
144
|
+
*/
|
|
145
|
+
export function getInMemoryTraceCollector() {
|
|
146
|
+
if (globalCollector instanceof InMemoryTraceCollector) {
|
|
147
|
+
return globalCollector;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=trace-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-wrapper.js","sourceRoot":"","sources":["../src/trace-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,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AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,eAAe,YAAY,sBAAsB,EAAE,CAAC;QACtD,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool definition
|
|
3
|
+
* INV-MCP-004: Tools MUST declare idempotency
|
|
4
|
+
*/
|
|
5
|
+
export interface MCPTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
inputSchema: MCPSchema;
|
|
9
|
+
/**
|
|
10
|
+
* Output schema for the tool result
|
|
11
|
+
* INV-MCP-006: Tools SHOULD declare output schemas
|
|
12
|
+
*/
|
|
13
|
+
outputSchema?: MCPSchema;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the tool is idempotent (can be safely retried)
|
|
16
|
+
* INV-MCP-004: Tools MUST declare idempotency
|
|
17
|
+
*/
|
|
18
|
+
idempotent?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Error codes that are safe to retry
|
|
21
|
+
*/
|
|
22
|
+
retryableErrors?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* MCP Schema (JSON Schema subset)
|
|
26
|
+
*/
|
|
27
|
+
export interface MCPSchema {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, MCPProperty>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* MCP Property definition (JSON Schema subset)
|
|
34
|
+
*/
|
|
35
|
+
export interface MCPProperty {
|
|
36
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
37
|
+
description?: string | undefined;
|
|
38
|
+
enum?: string[] | undefined;
|
|
39
|
+
items?: MCPProperty | undefined;
|
|
40
|
+
default?: unknown;
|
|
41
|
+
minItems?: number | undefined;
|
|
42
|
+
maxItems?: number | undefined;
|
|
43
|
+
minimum?: number | undefined;
|
|
44
|
+
maximum?: number | undefined;
|
|
45
|
+
properties?: Record<string, MCPProperty> | undefined;
|
|
46
|
+
required?: string[] | undefined;
|
|
47
|
+
additionalProperties?: MCPProperty | boolean | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* MCP Tool call request
|
|
51
|
+
*/
|
|
52
|
+
export interface MCPToolCall {
|
|
53
|
+
name: string;
|
|
54
|
+
arguments: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* MCP Tool call result
|
|
58
|
+
*/
|
|
59
|
+
export interface MCPToolResult {
|
|
60
|
+
content: MCPContent[];
|
|
61
|
+
isError?: boolean | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* MCP Content block
|
|
65
|
+
*/
|
|
66
|
+
export interface MCPContent {
|
|
67
|
+
type: 'text' | 'image' | 'resource';
|
|
68
|
+
text?: string | undefined;
|
|
69
|
+
data?: string | undefined;
|
|
70
|
+
mimeType?: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* MCP Server configuration
|
|
74
|
+
*/
|
|
75
|
+
export interface MCPServerConfig {
|
|
76
|
+
name: string;
|
|
77
|
+
version: string;
|
|
78
|
+
description?: string | undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Tool handler function
|
|
82
|
+
*/
|
|
83
|
+
export type ToolHandler = (args: Record<string, unknown>) => Promise<MCPToolResult>;
|
|
84
|
+
/**
|
|
85
|
+
* MCP message types
|
|
86
|
+
*/
|
|
87
|
+
export interface MCPRequest {
|
|
88
|
+
jsonrpc: '2.0';
|
|
89
|
+
id: string | number;
|
|
90
|
+
method: string;
|
|
91
|
+
params?: Record<string, unknown> | undefined;
|
|
92
|
+
}
|
|
93
|
+
export interface MCPResponse {
|
|
94
|
+
jsonrpc: '2.0';
|
|
95
|
+
id: string | number;
|
|
96
|
+
result?: unknown;
|
|
97
|
+
error?: MCPError | undefined;
|
|
98
|
+
}
|
|
99
|
+
export interface MCPError {
|
|
100
|
+
code: number;
|
|
101
|
+
message: string;
|
|
102
|
+
data?: unknown;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Standard MCP error codes
|
|
106
|
+
*/
|
|
107
|
+
export declare const MCPErrorCodes: {
|
|
108
|
+
readonly PARSE_ERROR: -32700;
|
|
109
|
+
readonly INVALID_REQUEST: -32600;
|
|
110
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
111
|
+
readonly INVALID_PARAMS: -32602;
|
|
112
|
+
readonly INTERNAL_ERROR: -32603;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* MCP Resource definition
|
|
116
|
+
*/
|
|
117
|
+
export interface MCPResource {
|
|
118
|
+
/** Resource URI (e.g., "automatosx://workflows") */
|
|
119
|
+
uri: string;
|
|
120
|
+
/** Display name */
|
|
121
|
+
name: string;
|
|
122
|
+
/** Description */
|
|
123
|
+
description?: string | undefined;
|
|
124
|
+
/** MIME type of resource content */
|
|
125
|
+
mimeType?: string | undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* MCP Resource content
|
|
129
|
+
*/
|
|
130
|
+
export interface MCPResourceContent {
|
|
131
|
+
/** Resource URI */
|
|
132
|
+
uri: string;
|
|
133
|
+
/** MIME type */
|
|
134
|
+
mimeType: string;
|
|
135
|
+
/** Text content */
|
|
136
|
+
text?: string | undefined;
|
|
137
|
+
/** Binary content (base64) */
|
|
138
|
+
blob?: string | undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resource handler function
|
|
142
|
+
*/
|
|
143
|
+
export type ResourceHandler = (uri: string, params?: Record<string, string>) => Promise<MCPResourceContent>;
|
|
144
|
+
/**
|
|
145
|
+
* MCP Prompt argument definition
|
|
146
|
+
*/
|
|
147
|
+
export interface MCPPromptArgument {
|
|
148
|
+
/** Argument name */
|
|
149
|
+
name: string;
|
|
150
|
+
/** Description */
|
|
151
|
+
description?: string | undefined;
|
|
152
|
+
/** Whether required */
|
|
153
|
+
required?: boolean | undefined;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* MCP Prompt definition
|
|
157
|
+
*/
|
|
158
|
+
export interface MCPPrompt {
|
|
159
|
+
/** Prompt name */
|
|
160
|
+
name: string;
|
|
161
|
+
/** Description */
|
|
162
|
+
description?: string | undefined;
|
|
163
|
+
/** Arguments */
|
|
164
|
+
arguments?: MCPPromptArgument[] | undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* MCP Prompt message
|
|
168
|
+
*/
|
|
169
|
+
export interface MCPPromptMessage {
|
|
170
|
+
/** Role */
|
|
171
|
+
role: 'user' | 'assistant';
|
|
172
|
+
/** Content */
|
|
173
|
+
content: {
|
|
174
|
+
type: 'text';
|
|
175
|
+
text: string;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Prompt handler function
|
|
180
|
+
*/
|
|
181
|
+
export type PromptHandler = (args: Record<string, string>) => Promise<{
|
|
182
|
+
description?: string;
|
|
183
|
+
messages: MCPPromptMessage[];
|
|
184
|
+
}>;
|
|
185
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,SAAS,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU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AC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAqHA;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,WAAW,EAAE,CAAC,KAAK;IACnB,eAAe,EAAE,CAAC,KAAK;IACvB,gBAAgB,EAAE,CAAC,KAAK;IACxB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;CACd,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Store Utility
|
|
3
|
+
*
|
|
4
|
+
* Stores large MCP results externally so they don't pollute conversation context.
|
|
5
|
+
* Uses the memory domain with a dedicated 'artifacts' namespace.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-MCP-RESP-005: Large results stored as artifacts with artifactRef
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Store an artifact and return its reference URI
|
|
12
|
+
*
|
|
13
|
+
* @param key - Artifact key (e.g., "bugfix:scan:12345")
|
|
14
|
+
* @param data - Data to store
|
|
15
|
+
* @returns Artifact reference URI (e.g., "ax://bugfix/scan:12345")
|
|
16
|
+
*/
|
|
17
|
+
export declare function storeArtifact(key: string, data: unknown): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieve an artifact by its reference URI
|
|
20
|
+
*
|
|
21
|
+
* @param ref - Artifact reference URI (e.g., "ax://bugfix/scan:12345")
|
|
22
|
+
* @returns The stored data, or undefined if not found
|
|
23
|
+
*/
|
|
24
|
+
export declare function retrieveArtifact(ref: string): Promise<unknown | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an artifact exists
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasArtifact(ref: string): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete an artifact
|
|
31
|
+
*/
|
|
32
|
+
export declare function deleteArtifact(ref: string): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* List artifacts by domain
|
|
35
|
+
*/
|
|
36
|
+
export declare function listArtifacts(domain: string): Promise<string[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Clear all artifacts (for testing)
|
|
39
|
+
*/
|
|
40
|
+
export declare function clearArtifacts(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get artifact cache size (for monitoring)
|
|
43
|
+
*/
|
|
44
|
+
export declare function getArtifactCacheSize(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Get total artifact cache memory estimate (rough)
|
|
47
|
+
*/
|
|
48
|
+
export declare function getArtifactCacheMemory(): number;
|
|
49
|
+
//# sourceMappingURL=artifact-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.d.ts","sourceRoot":"","sources":["../../src/utils/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAYhF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO/D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOlE;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAYrE;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAM/C"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Store Utility
|
|
3
|
+
*
|
|
4
|
+
* Stores large MCP results externally so they don't pollute conversation context.
|
|
5
|
+
* Uses the memory domain with a dedicated 'artifacts' namespace.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - INV-MCP-RESP-005: Large results stored as artifacts with artifactRef
|
|
9
|
+
*/
|
|
10
|
+
// In-memory artifact store for when memory domain is not available
|
|
11
|
+
const artifactCache = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Store an artifact and return its reference URI
|
|
14
|
+
*
|
|
15
|
+
* @param key - Artifact key (e.g., "bugfix:scan:12345")
|
|
16
|
+
* @param data - Data to store
|
|
17
|
+
* @returns Artifact reference URI (e.g., "ax://bugfix/scan:12345")
|
|
18
|
+
*/
|
|
19
|
+
export async function storeArtifact(key, data) {
|
|
20
|
+
// Store in memory cache
|
|
21
|
+
artifactCache.set(key, data);
|
|
22
|
+
// Generate reference URI
|
|
23
|
+
const [domain, ...rest] = key.split(':');
|
|
24
|
+
const id = rest.join(':') || key;
|
|
25
|
+
return `ax://${domain}/${id}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve an artifact by its reference URI
|
|
29
|
+
*
|
|
30
|
+
* @param ref - Artifact reference URI (e.g., "ax://bugfix/scan:12345")
|
|
31
|
+
* @returns The stored data, or undefined if not found
|
|
32
|
+
*/
|
|
33
|
+
export async function retrieveArtifact(ref) {
|
|
34
|
+
// Parse reference URI
|
|
35
|
+
const match = /^ax:\/\/([^/]+)\/(.+)$/.exec(ref);
|
|
36
|
+
if (!match) {
|
|
37
|
+
throw new Error(`Invalid artifact reference: ${ref}`);
|
|
38
|
+
}
|
|
39
|
+
const [, domain, id] = match;
|
|
40
|
+
const key = `${domain}:${id}`;
|
|
41
|
+
// Retrieve from memory cache
|
|
42
|
+
return artifactCache.get(key);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if an artifact exists
|
|
46
|
+
*/
|
|
47
|
+
export async function hasArtifact(ref) {
|
|
48
|
+
const match = /^ax:\/\/([^/]+)\/(.+)$/.exec(ref);
|
|
49
|
+
if (!match)
|
|
50
|
+
return false;
|
|
51
|
+
const [, domain, id] = match;
|
|
52
|
+
const key = `${domain}:${id}`;
|
|
53
|
+
return artifactCache.has(key);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Delete an artifact
|
|
57
|
+
*/
|
|
58
|
+
export async function deleteArtifact(ref) {
|
|
59
|
+
const match = /^ax:\/\/([^/]+)\/(.+)$/.exec(ref);
|
|
60
|
+
if (!match)
|
|
61
|
+
return false;
|
|
62
|
+
const [, domain, id] = match;
|
|
63
|
+
const key = `${domain}:${id}`;
|
|
64
|
+
return artifactCache.delete(key);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* List artifacts by domain
|
|
68
|
+
*/
|
|
69
|
+
export async function listArtifacts(domain) {
|
|
70
|
+
const prefix = `${domain}:`;
|
|
71
|
+
const refs = [];
|
|
72
|
+
for (const key of artifactCache.keys()) {
|
|
73
|
+
if (key.startsWith(prefix)) {
|
|
74
|
+
const id = key.slice(prefix.length);
|
|
75
|
+
refs.push(`ax://${domain}/${id}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return refs;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Clear all artifacts (for testing)
|
|
82
|
+
*/
|
|
83
|
+
export function clearArtifacts() {
|
|
84
|
+
artifactCache.clear();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get artifact cache size (for monitoring)
|
|
88
|
+
*/
|
|
89
|
+
export function getArtifactCacheSize() {
|
|
90
|
+
return artifactCache.size;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get total artifact cache memory estimate (rough)
|
|
94
|
+
*/
|
|
95
|
+
export function getArtifactCacheMemory() {
|
|
96
|
+
let total = 0;
|
|
97
|
+
for (const value of artifactCache.values()) {
|
|
98
|
+
total += JSON.stringify(value).length;
|
|
99
|
+
}
|
|
100
|
+
return total;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=artifact-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.js","sourceRoot":"","sources":["../../src/utils/artifact-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,mEAAmE;AACnE,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,IAAa;IAEb,wBAAwB;IACxB,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAE7B,yBAAyB;IACzB,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;IACjC,OAAO,QAAQ,MAAM,IAAI,EAAE,EAAE,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,sBAAsB;IACtB,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC;IAC7B,MAAM,GAAG,GAAG,GAAG,MAAM,IAAI,EAAE,EAAE,CAAC;IAE9B,6BAA6B;IAC7B,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;A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CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,aAAa,CAAC,IAAI,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;QAC3C,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACxC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server Utilities
|
|
3
|
+
*/
|
|
4
|
+
export { wrapResponse, successResponse, errorResponse, createListResponse, createScanResponse, createCountSummary, createListSummary, type ResponseLimits, type MCPResponseContract, type WrapResponseOptions, type ListResponseOptions, type ScanResultItem, type ScanResponseOptions, type ArtifactStoreFn, DEFAULT_LIMITS, } from './response.js';
|
|
5
|
+
export { storeArtifact, retrieveArtifact, hasArtifact, deleteArtifact, listArtifacts, clearArtifacts, getArtifactCacheSize, getArtifactCacheMemory, } from './artifact-store.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EAEjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EAEpB,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server Utilities
|
|
3
|
+
*/
|
|
4
|
+
export {
|
|
5
|
+
// Response wrapper
|
|
6
|
+
wrapResponse, successResponse, errorResponse, createListResponse, createScanResponse, createCountSummary, createListSummary,
|
|
7
|
+
// Constants
|
|
8
|
+
DEFAULT_LIMITS, } from './response.js';
|
|
9
|
+
export { storeArtifact, retrieveArtifact, hasArtifact, deleteArtifact, listArtifacts, clearArtifacts, getArtifactCacheSize, getArtifactCacheMemory, } from './artifact-store.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO;AACL,mBAAmB;AACnB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB;AASjB,YAAY;AACZ,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC"}
|