@grafema/mcp 0.1.0-alpha.1

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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Grafema MCP Server
4
+ *
5
+ * Provides code analysis tools via Model Context Protocol.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
package/dist/server.js ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Grafema MCP Server
4
+ *
5
+ * Provides code analysis tools via Model Context Protocol.
6
+ */
7
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
10
+ import { TOOLS } from './definitions.js';
11
+ import { initializeFromArgs, setupLogging, getProjectPath } from './state.js';
12
+ import { textResult, errorResult, log } from './utils.js';
13
+ import { discoverServices } from './analysis.js';
14
+ import { handleQueryGraph, handleFindCalls, handleFindNodes, handleTraceAlias, handleTraceDataFlow, handleCheckInvariant, handleAnalyzeProject, handleGetAnalysisStatus, handleGetStats, handleGetSchema, handleCreateGuarantee, handleListGuarantees, handleCheckGuarantees, handleDeleteGuarantee, handleGetCoverage, handleGetDocumentation, handleReportIssue, } from './handlers.js';
15
+ // Initialize from command line args
16
+ initializeFromArgs();
17
+ setupLogging();
18
+ const projectPath = getProjectPath();
19
+ log(`[Grafema MCP] Starting server for project: ${projectPath}`);
20
+ // Create MCP server
21
+ const server = new Server({
22
+ name: 'grafema-mcp',
23
+ version: '0.1.0',
24
+ }, {
25
+ capabilities: {
26
+ tools: {},
27
+ },
28
+ });
29
+ // List available tools
30
+ server.setRequestHandler(ListToolsRequestSchema, async (_request, _extra) => {
31
+ return { tools: TOOLS };
32
+ });
33
+ // Handle tool calls
34
+ server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
35
+ void extra; // suppress unused warning
36
+ const { name, arguments: args } = request.params;
37
+ const startTime = Date.now();
38
+ const argsPreview = args ? JSON.stringify(args).slice(0, 200) : '{}';
39
+ log(`[Grafema MCP] ▶ ${name} args=${argsPreview}`);
40
+ try {
41
+ let result;
42
+ switch (name) {
43
+ case 'query_graph':
44
+ result = await handleQueryGraph(args);
45
+ break;
46
+ case 'find_calls':
47
+ result = await handleFindCalls(args);
48
+ break;
49
+ case 'find_nodes':
50
+ result = await handleFindNodes(args);
51
+ break;
52
+ case 'trace_alias':
53
+ result = await handleTraceAlias(args);
54
+ break;
55
+ case 'trace_dataflow':
56
+ result = await handleTraceDataFlow(args);
57
+ break;
58
+ case 'check_invariant':
59
+ result = await handleCheckInvariant(args);
60
+ break;
61
+ case 'discover_services':
62
+ const services = await discoverServices();
63
+ result = textResult(`Found ${services.length} service(s):\n${JSON.stringify(services, null, 2)}`);
64
+ break;
65
+ case 'analyze_project':
66
+ result = await handleAnalyzeProject(args);
67
+ break;
68
+ case 'get_analysis_status':
69
+ result = await handleGetAnalysisStatus();
70
+ break;
71
+ case 'get_stats':
72
+ result = await handleGetStats();
73
+ break;
74
+ case 'get_schema':
75
+ result = await handleGetSchema(args);
76
+ break;
77
+ case 'create_guarantee':
78
+ result = await handleCreateGuarantee(args);
79
+ break;
80
+ case 'list_guarantees':
81
+ result = await handleListGuarantees();
82
+ break;
83
+ case 'check_guarantees':
84
+ result = await handleCheckGuarantees(args);
85
+ break;
86
+ case 'delete_guarantee':
87
+ result = await handleDeleteGuarantee(args);
88
+ break;
89
+ case 'get_coverage':
90
+ result = await handleGetCoverage(args);
91
+ break;
92
+ case 'get_documentation':
93
+ result = await handleGetDocumentation(args);
94
+ break;
95
+ case 'report_issue':
96
+ result = await handleReportIssue(args);
97
+ break;
98
+ default:
99
+ result = errorResult(`Unknown tool: ${name}`);
100
+ }
101
+ const duration = Date.now() - startTime;
102
+ const resultSize = JSON.stringify(result).length;
103
+ const status = result.isError ? '✗' : '✓';
104
+ log(`[Grafema MCP] ${status} ${name} completed in ${duration}ms (${resultSize} bytes)`);
105
+ return result;
106
+ }
107
+ catch (error) {
108
+ const duration = Date.now() - startTime;
109
+ log(`[Grafema MCP] ✗ ${name} FAILED after ${duration}ms: ${error.message}`);
110
+ return errorResult(error.message);
111
+ }
112
+ });
113
+ // Main entry point
114
+ async function main() {
115
+ const transport = new StdioServerTransport();
116
+ await server.connect(transport);
117
+ log('[Grafema MCP] Server connected via stdio');
118
+ }
119
+ main().catch((error) => {
120
+ log(`[Grafema MCP] Fatal error: ${error.message}`);
121
+ process.exit(1);
122
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * MCP Server State Management
3
+ */
4
+ import { GuaranteeManager, GuaranteeAPI } from '@grafema/core';
5
+ import type { AnalysisStatus } from './types.js';
6
+ import type { GraphBackend } from '@grafema/types';
7
+ export declare function getProjectPath(): string;
8
+ export declare function getIsAnalyzed(): boolean;
9
+ export declare function getAnalysisStatus(): AnalysisStatus;
10
+ export declare function getBackgroundPid(): number | null;
11
+ export declare function getGuaranteeManager(): GuaranteeManager | null;
12
+ export declare function getGuaranteeAPI(): GuaranteeAPI | null;
13
+ export declare function setProjectPath(path: string): void;
14
+ export declare function setIsAnalyzed(value: boolean): void;
15
+ export declare function setAnalysisStatus(status: Partial<AnalysisStatus>): void;
16
+ export declare function setBackgroundPid(pid: number | null): void;
17
+ export declare function updateAnalysisTimings(timings: Partial<AnalysisStatus['timings']>): void;
18
+ export declare function getOrCreateBackend(): Promise<GraphBackend>;
19
+ export declare function getBackendIfExists(): GraphBackend | null;
20
+ export declare function setupLogging(): void;
21
+ export declare function initializeFromArgs(): void;
22
+ export declare function cleanup(): Promise<void>;
23
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAqB,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgCnD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAElD;AAED,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAE7D;AAED,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAElD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAEvE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAEzD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,CAEvF;AAGD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CAgChE;AAkBD,wBAAgB,kBAAkB,IAAI,YAAY,GAAG,IAAI,CAExD;AAGD,wBAAgB,YAAY,IAAI,IAAI,CAMnC;AAGD,wBAAgB,kBAAkB,IAAI,IAAI,CAQzC;AAGD,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAI7C"}
package/dist/state.js ADDED
@@ -0,0 +1,138 @@
1
+ /**
2
+ * MCP Server State Management
3
+ */
4
+ import { join } from 'path';
5
+ import { existsSync, mkdirSync } from 'fs';
6
+ import { RFDBServerBackend, GuaranteeManager, GuaranteeAPI } from '@grafema/core';
7
+ import { loadConfig } from './config.js';
8
+ import { log, initLogger } from './utils.js';
9
+ // === GLOBAL STATE ===
10
+ let projectPath = process.cwd();
11
+ let backend = null;
12
+ let isAnalyzed = false;
13
+ let backgroundPid = null;
14
+ // Guarantee managers
15
+ let guaranteeManager = null;
16
+ let guaranteeAPI = null;
17
+ let analysisStatus = {
18
+ running: false,
19
+ phase: null,
20
+ message: null,
21
+ servicesDiscovered: 0,
22
+ servicesAnalyzed: 0,
23
+ startTime: null,
24
+ endTime: null,
25
+ error: null,
26
+ timings: {
27
+ discovery: null,
28
+ indexing: null,
29
+ analysis: null,
30
+ enrichment: null,
31
+ validation: null,
32
+ total: null,
33
+ },
34
+ };
35
+ // === GETTERS ===
36
+ export function getProjectPath() {
37
+ return projectPath;
38
+ }
39
+ export function getIsAnalyzed() {
40
+ return isAnalyzed;
41
+ }
42
+ export function getAnalysisStatus() {
43
+ return analysisStatus;
44
+ }
45
+ export function getBackgroundPid() {
46
+ return backgroundPid;
47
+ }
48
+ export function getGuaranteeManager() {
49
+ return guaranteeManager;
50
+ }
51
+ export function getGuaranteeAPI() {
52
+ return guaranteeAPI;
53
+ }
54
+ // === SETTERS ===
55
+ export function setProjectPath(path) {
56
+ projectPath = path;
57
+ }
58
+ export function setIsAnalyzed(value) {
59
+ isAnalyzed = value;
60
+ }
61
+ export function setAnalysisStatus(status) {
62
+ analysisStatus = { ...analysisStatus, ...status };
63
+ }
64
+ export function setBackgroundPid(pid) {
65
+ backgroundPid = pid;
66
+ }
67
+ export function updateAnalysisTimings(timings) {
68
+ analysisStatus.timings = { ...analysisStatus.timings, ...timings };
69
+ }
70
+ // === BACKEND ===
71
+ export async function getOrCreateBackend() {
72
+ if (backend)
73
+ return backend;
74
+ const grafemaDir = join(projectPath, '.grafema');
75
+ const dbPath = join(grafemaDir, 'graph.rfdb');
76
+ if (!existsSync(grafemaDir)) {
77
+ mkdirSync(grafemaDir, { recursive: true });
78
+ }
79
+ const config = loadConfig(projectPath);
80
+ // Socket path from config, or let RFDBServerBackend derive it from dbPath
81
+ const socketPath = config.analysis?.parallel?.socketPath;
82
+ log(`[Grafema MCP] Using RFDB server backend: socket=${socketPath || 'auto'}, db=${dbPath}`);
83
+ const rfdbBackend = new RFDBServerBackend({ socketPath, dbPath });
84
+ await rfdbBackend.connect();
85
+ backend = rfdbBackend;
86
+ const nodeCount = await backend.nodeCount();
87
+ if (nodeCount > 0) {
88
+ isAnalyzed = true;
89
+ log(`[Grafema MCP] Connected to existing database: ${nodeCount} nodes`);
90
+ }
91
+ else {
92
+ log(`[Grafema MCP] Empty database, analysis needed`);
93
+ }
94
+ // Initialize guarantee managers
95
+ initializeGuaranteeManagers(rfdbBackend);
96
+ return backend;
97
+ }
98
+ /**
99
+ * Initialize GuaranteeManager (Datalog-based) and GuaranteeAPI (contract-based)
100
+ */
101
+ function initializeGuaranteeManagers(rfdbBackend) {
102
+ // GuaranteeManager for Datalog-based guarantees
103
+ // Cast to GuaranteeGraph interface expected by GuaranteeManager
104
+ const guaranteeGraph = rfdbBackend;
105
+ guaranteeManager = new GuaranteeManager(guaranteeGraph, projectPath);
106
+ log(`[Grafema MCP] GuaranteeManager initialized`);
107
+ // GuaranteeAPI for contract-based guarantees
108
+ const guaranteeGraphBackend = rfdbBackend;
109
+ guaranteeAPI = new GuaranteeAPI(guaranteeGraphBackend);
110
+ log(`[Grafema MCP] GuaranteeAPI initialized`);
111
+ }
112
+ export function getBackendIfExists() {
113
+ return backend;
114
+ }
115
+ // === LOGGING SETUP ===
116
+ export function setupLogging() {
117
+ const grafemaDir = join(projectPath, '.grafema');
118
+ if (!existsSync(grafemaDir)) {
119
+ mkdirSync(grafemaDir, { recursive: true });
120
+ }
121
+ initLogger(grafemaDir);
122
+ }
123
+ // === INITIALIZATION ===
124
+ export function initializeFromArgs() {
125
+ const args = process.argv.slice(2);
126
+ for (let i = 0; i < args.length; i++) {
127
+ if (args[i] === '--project' && args[i + 1]) {
128
+ projectPath = args[i + 1];
129
+ i++;
130
+ }
131
+ }
132
+ }
133
+ // === CLEANUP ===
134
+ export async function cleanup() {
135
+ if (backend && 'close' in backend && typeof backend.close === 'function') {
136
+ await backend.close();
137
+ }
138
+ }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * MCP Server Types
3
+ */
4
+ import type { WriteStream } from 'fs';
5
+ export interface AnalysisTimings {
6
+ discovery: number | null;
7
+ indexing: number | null;
8
+ analysis: number | null;
9
+ enrichment: number | null;
10
+ validation: number | null;
11
+ total: number | null;
12
+ }
13
+ export interface AnalysisStatus {
14
+ running: boolean;
15
+ phase: string | null;
16
+ message: string | null;
17
+ servicesDiscovered: number;
18
+ servicesAnalyzed: number;
19
+ startTime: number | null;
20
+ endTime: number | null;
21
+ error: string | null;
22
+ timings: AnalysisTimings;
23
+ }
24
+ export interface PaginationParams {
25
+ limit: number;
26
+ offset: number;
27
+ returned: number;
28
+ total?: number;
29
+ hasMore: boolean;
30
+ }
31
+ export interface GrafemaConfig {
32
+ project_path?: string;
33
+ backend?: 'local' | 'rfdb';
34
+ rfdb_socket?: string;
35
+ plugins?: string[];
36
+ ignore_patterns?: string[];
37
+ }
38
+ export interface QueryGraphArgs {
39
+ query: string;
40
+ limit?: number;
41
+ offset?: number;
42
+ format?: 'table' | 'json' | 'tree';
43
+ }
44
+ export interface FindCallsArgs {
45
+ target: string;
46
+ limit?: number;
47
+ offset?: number;
48
+ include_indirect?: boolean;
49
+ }
50
+ export interface TraceAliasArgs {
51
+ identifier: string;
52
+ file?: string;
53
+ max_depth?: number;
54
+ }
55
+ export interface TraceDataFlowArgs {
56
+ source: string;
57
+ file?: string;
58
+ direction?: 'forward' | 'backward' | 'both';
59
+ max_depth?: number;
60
+ limit?: number;
61
+ }
62
+ export interface CheckInvariantArgs {
63
+ rule: string;
64
+ name?: string;
65
+ }
66
+ export interface GetSchemaArgs {
67
+ type?: 'nodes' | 'edges' | 'all';
68
+ }
69
+ export interface GetValueSetArgs {
70
+ node_id: string;
71
+ property?: string;
72
+ }
73
+ export interface FindNodesArgs {
74
+ type?: string;
75
+ name?: string;
76
+ file?: string;
77
+ limit?: number;
78
+ offset?: number;
79
+ }
80
+ export interface AnalyzeProjectArgs {
81
+ service?: string;
82
+ force?: boolean;
83
+ index_only?: boolean;
84
+ }
85
+ export interface GetCoverageArgs {
86
+ path?: string;
87
+ depth?: number;
88
+ }
89
+ export interface GetDocumentationArgs {
90
+ topic?: string;
91
+ }
92
+ export type GuaranteePriority = 'critical' | 'important' | 'observed' | 'tracked';
93
+ export type GuaranteeStatus = 'discovered' | 'reviewed' | 'active' | 'changing' | 'deprecated';
94
+ export interface CreateGuaranteeArgs {
95
+ name: string;
96
+ rule?: string;
97
+ description?: string;
98
+ severity?: 'error' | 'warning' | 'info';
99
+ type?: 'guarantee:queue' | 'guarantee:api' | 'guarantee:permission';
100
+ priority?: GuaranteePriority;
101
+ status?: GuaranteeStatus;
102
+ owner?: string;
103
+ schema?: Record<string, unknown>;
104
+ condition?: string;
105
+ governs?: string[];
106
+ }
107
+ export interface CheckGuaranteesArgs {
108
+ names?: string[];
109
+ }
110
+ export interface DeleteGuaranteeArgs {
111
+ name: string;
112
+ }
113
+ export interface ExportGuaranteesArgs {
114
+ format?: 'json' | 'yaml';
115
+ }
116
+ export interface ImportGuaranteesArgs {
117
+ guarantees: Array<{
118
+ name: string;
119
+ rule: string;
120
+ description?: string;
121
+ severity?: string;
122
+ }>;
123
+ merge?: boolean;
124
+ }
125
+ export interface GuaranteeDriftArgs {
126
+ baseline?: string;
127
+ }
128
+ export interface CheckGuaranteeFeasibilityArgs {
129
+ rule: string;
130
+ }
131
+ export interface ToolResult {
132
+ [x: string]: unknown;
133
+ content: Array<{
134
+ type: 'text';
135
+ text: string;
136
+ }>;
137
+ isError?: boolean;
138
+ _meta?: Record<string, unknown>;
139
+ }
140
+ export interface GraphBackend {
141
+ nodeCount(): Promise<number>;
142
+ edgeCount(): Promise<number>;
143
+ countNodesByType(types?: string[] | null): Promise<Record<string, number>>;
144
+ countEdgesByType(types?: string[] | null): Promise<Record<string, number>>;
145
+ getNode(id: string): Promise<GraphNode | null>;
146
+ findByType(type: string): Promise<string[]>;
147
+ findByAttr(query: Record<string, unknown>): Promise<string[]>;
148
+ getOutgoingEdges(id: string, types?: string[] | null): Promise<GraphEdge[]>;
149
+ getIncomingEdges(id: string, types?: string[] | null): Promise<GraphEdge[]>;
150
+ queryNodes(filter: Record<string, unknown>): AsyncIterable<GraphNode>;
151
+ getAllNodes(filter?: Record<string, unknown>): Promise<GraphNode[]>;
152
+ runDatalogQuery?(query: string): Promise<unknown[]>;
153
+ close?(): Promise<void>;
154
+ }
155
+ export interface GraphNode {
156
+ id: string;
157
+ type: string;
158
+ name: string;
159
+ file?: string;
160
+ line?: number;
161
+ [key: string]: unknown;
162
+ }
163
+ export interface GraphEdge {
164
+ src: string;
165
+ dst: string;
166
+ type: string;
167
+ edgeType?: string;
168
+ [key: string]: unknown;
169
+ }
170
+ export interface MCPState {
171
+ projectPath: string;
172
+ backend: GraphBackend | null;
173
+ isAnalyzed: boolean;
174
+ analysisStatus: AnalysisStatus;
175
+ logStream: WriteStream | null;
176
+ backgroundPid: number | null;
177
+ }
178
+ export interface FileClassification {
179
+ category: 'source' | 'config' | 'test' | 'doc' | 'asset' | 'generated' | 'other';
180
+ language?: string;
181
+ framework?: string;
182
+ }
183
+ export interface ExtensionGroup {
184
+ [ext: string]: string[];
185
+ }
186
+ export interface AnalyzerSuggestion {
187
+ name: string;
188
+ reason: string;
189
+ priority: number;
190
+ }
191
+ export interface ReportIssueArgs {
192
+ title: string;
193
+ description: string;
194
+ context?: string;
195
+ labels?: string[];
196
+ }
197
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,W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B;AAGD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAGD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * MCP Server Types
3
+ */
4
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * MCP Server Utilities
3
+ */
4
+ import type { PaginationParams, ToolResult } from './types.js';
5
+ export declare const DEFAULT_LIMIT = 10;
6
+ export declare const MAX_LIMIT = 500;
7
+ export declare const DEFAULT_RESPONSE_SIZE_LIMIT = 100000;
8
+ export declare function initLogger(grafemaDir: string): void;
9
+ export declare function getLogsDir(): string | null;
10
+ export declare function log(msg: string): void;
11
+ export declare function guardResponseSize(text: string, maxSize?: number): string;
12
+ export declare function normalizeLimit(limit: number | undefined | null): number;
13
+ export declare function formatPaginationInfo(params: PaginationParams): string;
14
+ export declare function findSimilarTypes(queriedType: string, availableTypes: string[], maxDistance?: number): string[];
15
+ export declare function levenshtein(a: string, b: string): number;
16
+ export declare function serializeBigInt(obj: unknown): unknown;
17
+ export declare function textResult(text: string): ToolResult;
18
+ export declare function errorResult(message: string): ToolResult;
19
+ export declare function jsonResult(data: unknown, pretty?: boolean): ToolResult;
20
+ export declare function isProcessRunning(pid: number): boolean;
21
+ export declare function formatDuration(ms: number): string;
22
+ export declare function formatNumber(n: number): string;
23
+ export declare function truncate(s: string, maxLen: number): string;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG/D,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,SAAS,MAAM,CAAC;AAC7B,eAAO,MAAM,2BAA2B,SAAU,CAAC;AAkCnD,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAOnD;AAED,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAE1C;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CASrC;AAGD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAoC,GAAG,MAAM,CAOrG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAGvE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAarE;AAGD,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EAAE,EACxB,WAAW,GAAE,MAAU,GACtB,MAAM,EAAE,CAYV;AAGD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAwBxD;AAGD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAYrD;AAGD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAInD;AAED,wBAAgB,WAAW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