@memlab/mcp-server 2.0.0
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/README.md +285 -0
- package/bin/memlab-mcp.js +3 -0
- package/dist/heap-state.d.ts +14 -0
- package/dist/heap-state.d.ts.map +1 -0
- package/dist/heap-state.js +25 -0
- package/dist/heap-state.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/aggregate-nodes.d.ts +12 -0
- package/dist/tools/aggregate-nodes.d.ts.map +1 -0
- package/dist/tools/aggregate-nodes.js +136 -0
- package/dist/tools/aggregate-nodes.js.map +1 -0
- package/dist/tools/class-histogram.d.ts +12 -0
- package/dist/tools/class-histogram.d.ts.map +1 -0
- package/dist/tools/class-histogram.js +94 -0
- package/dist/tools/class-histogram.js.map +1 -0
- package/dist/tools/closure-inspection.d.ts +12 -0
- package/dist/tools/closure-inspection.d.ts.map +1 -0
- package/dist/tools/closure-inspection.js +107 -0
- package/dist/tools/closure-inspection.js.map +1 -0
- package/dist/tools/detached-dom.d.ts +12 -0
- package/dist/tools/detached-dom.d.ts.map +1 -0
- package/dist/tools/detached-dom.js +53 -0
- package/dist/tools/detached-dom.js.map +1 -0
- package/dist/tools/dominator-subtree.d.ts +12 -0
- package/dist/tools/dominator-subtree.d.ts.map +1 -0
- package/dist/tools/dominator-subtree.js +77 -0
- package/dist/tools/dominator-subtree.js.map +1 -0
- package/dist/tools/duplicated-strings.d.ts +12 -0
- package/dist/tools/duplicated-strings.d.ts.map +1 -0
- package/dist/tools/duplicated-strings.js +78 -0
- package/dist/tools/duplicated-strings.js.map +1 -0
- package/dist/tools/eval.d.ts +12 -0
- package/dist/tools/eval.d.ts.map +1 -0
- package/dist/tools/eval.js +119 -0
- package/dist/tools/eval.js.map +1 -0
- package/dist/tools/find-by-property.d.ts +12 -0
- package/dist/tools/find-by-property.d.ts.map +1 -0
- package/dist/tools/find-by-property.js +77 -0
- package/dist/tools/find-by-property.js.map +1 -0
- package/dist/tools/find-nodes-by-class.d.ts +12 -0
- package/dist/tools/find-nodes-by-class.d.ts.map +1 -0
- package/dist/tools/find-nodes-by-class.js +38 -0
- package/dist/tools/find-nodes-by-class.js.map +1 -0
- package/dist/tools/for-each.d.ts +12 -0
- package/dist/tools/for-each.d.ts.map +1 -0
- package/dist/tools/for-each.js +185 -0
- package/dist/tools/for-each.js.map +1 -0
- package/dist/tools/get-node.d.ts +12 -0
- package/dist/tools/get-node.d.ts.map +1 -0
- package/dist/tools/get-node.js +51 -0
- package/dist/tools/get-node.js.map +1 -0
- package/dist/tools/get-property.d.ts +12 -0
- package/dist/tools/get-property.d.ts.map +1 -0
- package/dist/tools/get-property.js +88 -0
- package/dist/tools/get-property.js.map +1 -0
- package/dist/tools/get-references.d.ts +12 -0
- package/dist/tools/get-references.d.ts.map +1 -0
- package/dist/tools/get-references.js +61 -0
- package/dist/tools/get-references.js.map +1 -0
- package/dist/tools/get-referrers.d.ts +12 -0
- package/dist/tools/get-referrers.d.ts.map +1 -0
- package/dist/tools/get-referrers.js +61 -0
- package/dist/tools/get-referrers.js.map +1 -0
- package/dist/tools/global-variables.d.ts +12 -0
- package/dist/tools/global-variables.d.ts.map +1 -0
- package/dist/tools/global-variables.js +331 -0
- package/dist/tools/global-variables.js.map +1 -0
- package/dist/tools/largest-objects.d.ts +12 -0
- package/dist/tools/largest-objects.d.ts.map +1 -0
- package/dist/tools/largest-objects.js +32 -0
- package/dist/tools/largest-objects.js.map +1 -0
- package/dist/tools/load-snapshot.d.ts +12 -0
- package/dist/tools/load-snapshot.d.ts.map +1 -0
- package/dist/tools/load-snapshot.js +39 -0
- package/dist/tools/load-snapshot.js.map +1 -0
- package/dist/tools/object-shape.d.ts +12 -0
- package/dist/tools/object-shape.d.ts.map +1 -0
- package/dist/tools/object-shape.js +86 -0
- package/dist/tools/object-shape.js.map +1 -0
- package/dist/tools/reports.d.ts +12 -0
- package/dist/tools/reports.d.ts.map +1 -0
- package/dist/tools/reports.js +540 -0
- package/dist/tools/reports.js.map +1 -0
- package/dist/tools/retainer-trace.d.ts +12 -0
- package/dist/tools/retainer-trace.d.ts.map +1 -0
- package/dist/tools/retainer-trace.js +68 -0
- package/dist/tools/retainer-trace.js.map +1 -0
- package/dist/tools/search-nodes.d.ts +12 -0
- package/dist/tools/search-nodes.d.ts.map +1 -0
- package/dist/tools/search-nodes.js +85 -0
- package/dist/tools/search-nodes.js.map +1 -0
- package/dist/tools/snapshot-summary.d.ts +12 -0
- package/dist/tools/snapshot-summary.d.ts.map +1 -0
- package/dist/tools/snapshot-summary.js +73 -0
- package/dist/tools/snapshot-summary.js.map +1 -0
- package/dist/tools/stale-collections.d.ts +12 -0
- package/dist/tools/stale-collections.d.ts.map +1 -0
- package/dist/tools/stale-collections.js +97 -0
- package/dist/tools/stale-collections.js.map +1 -0
- package/dist/utils.d.ts +82 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +220 -0
- package/dist/utils.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { getSnapshot } from '../heap-state.js';
|
|
12
|
+
import { serializeNodeDetail, formatBytes, formatNumber, errorResult, textResult, } from '../utils.js';
|
|
13
|
+
export function registerGetProperty(server) {
|
|
14
|
+
server.tool('memlab_get_property', 'Look up a specific property (outgoing edge) of a heap node by name and return the target node with full details. Useful for traversing the object graph step by step (e.g., get the __proto__, stateNode, or memoizedState of a node).', {
|
|
15
|
+
node_id: z.number().describe('The numeric ID of the heap node'),
|
|
16
|
+
property_name: z
|
|
17
|
+
.string()
|
|
18
|
+
.describe('The property/edge name to look up (e.g., "__proto__", "stateNode", "0")'),
|
|
19
|
+
edge_type: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('Optional edge type filter (property, element, context, internal, hidden, shortcut, weak)'),
|
|
23
|
+
}, async ({ node_id, property_name, edge_type }) => {
|
|
24
|
+
try {
|
|
25
|
+
const snapshot = getSnapshot();
|
|
26
|
+
const node = snapshot.getNodeById(node_id);
|
|
27
|
+
if (!node) {
|
|
28
|
+
return errorResult(`Node with id ${node_id} not found`);
|
|
29
|
+
}
|
|
30
|
+
const matching = node.references.filter(edge => {
|
|
31
|
+
if (String(edge.name_or_index) !== property_name)
|
|
32
|
+
return false;
|
|
33
|
+
if (edge_type && edge.type !== edge_type)
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
if (matching.length === 0) {
|
|
38
|
+
const available = node.references
|
|
39
|
+
.filter(e => e.type === 'property' ||
|
|
40
|
+
e.type === 'element' ||
|
|
41
|
+
e.type === 'context')
|
|
42
|
+
.slice(0, 20)
|
|
43
|
+
.map(e => `${e.type}:${String(e.name_or_index)}`);
|
|
44
|
+
return textResult(`Property "${property_name}" not found on @${node_id} ${node.name}${edge_type ? ` (type filter: ${edge_type})` : ''}\n\nAvailable properties: ${available.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
const formatTarget = (d, edgeName, edgeType) => {
|
|
47
|
+
const lines = [
|
|
48
|
+
`**Source:** @${node.id} ${node.name} (${node.type})`,
|
|
49
|
+
`**Edge:** ${edgeName} (${edgeType})`,
|
|
50
|
+
'',
|
|
51
|
+
`**Target ID:** @${d.id}`,
|
|
52
|
+
`**Target Name:** ${d.name}`,
|
|
53
|
+
`**Target Type:** ${d.type}`,
|
|
54
|
+
`**Self Size:** ${formatBytes(d.self_size)}`,
|
|
55
|
+
`**Retained Size:** ${formatBytes(d.retained_size)}`,
|
|
56
|
+
`**Edges Out:** ${formatNumber(d.edge_count)}`,
|
|
57
|
+
`**Referrers:** ${formatNumber(d.referrer_count)}`,
|
|
58
|
+
`**Detached:** ${d.is_detached ? 'Yes' : 'No'}`,
|
|
59
|
+
];
|
|
60
|
+
if (d.location) {
|
|
61
|
+
lines.push(`**Location:** script ${d.location.script_id}, line ${d.location.line}, col ${d.location.column}`);
|
|
62
|
+
}
|
|
63
|
+
if (d.string_value !== undefined) {
|
|
64
|
+
const val = d.string_value.length > 200
|
|
65
|
+
? d.string_value.slice(0, 200) + '...'
|
|
66
|
+
: d.string_value;
|
|
67
|
+
lines.push(`**String Value:** "${val}"`);
|
|
68
|
+
}
|
|
69
|
+
return lines.join('\n');
|
|
70
|
+
};
|
|
71
|
+
if (matching.length === 1) {
|
|
72
|
+
const edge = matching[0];
|
|
73
|
+
const detail = serializeNodeDetail(edge.toNode);
|
|
74
|
+
return textResult(formatTarget(detail, String(edge.name_or_index), edge.type));
|
|
75
|
+
}
|
|
76
|
+
// Multiple matches
|
|
77
|
+
const sections = matching.map((edge, i) => {
|
|
78
|
+
const detail = serializeNodeDetail(edge.toNode);
|
|
79
|
+
return `### Match ${i + 1}\n${formatTarget(detail, String(edge.name_or_index), edge.type)}`;
|
|
80
|
+
});
|
|
81
|
+
return textResult(sections.join('\n\n'));
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return errorResult(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=get-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-property.js","sourceRoot":"","sources":["../../src/tools/get-property.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,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C;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
11
|
+
export declare function registerGetReferences(server: McpServer): void;
|
|
12
|
+
//# sourceMappingURL=get-references.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-references.d.ts","sourceRoot":"","sources":["../../src/tools/get-references.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAWvE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAuD7D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { getSnapshot } from '../heap-state.js';
|
|
12
|
+
import { formatBytes, formatNumber, markdownTable, errorResult, textResult, } from '../utils.js';
|
|
13
|
+
export function registerGetReferences(server) {
|
|
14
|
+
server.tool('memlab_get_references', 'Get outgoing edges (references) from a heap node, sorted by target retained size. Shows what objects this node points to.', {
|
|
15
|
+
node_id: z.number().describe('The numeric ID of the heap node'),
|
|
16
|
+
limit: z
|
|
17
|
+
.number()
|
|
18
|
+
.optional()
|
|
19
|
+
.default(30)
|
|
20
|
+
.describe('Maximum number of references to return (default 30)'),
|
|
21
|
+
}, async ({ node_id, limit }) => {
|
|
22
|
+
try {
|
|
23
|
+
const snapshot = getSnapshot();
|
|
24
|
+
const node = snapshot.getNodeById(node_id);
|
|
25
|
+
if (!node) {
|
|
26
|
+
return errorResult(`Node with id ${node_id} not found`);
|
|
27
|
+
}
|
|
28
|
+
const edges = node.references
|
|
29
|
+
.slice()
|
|
30
|
+
.sort((a, b) => b.toNode.retainedSize - a.toNode.retainedSize)
|
|
31
|
+
.slice(0, limit);
|
|
32
|
+
const lines = [
|
|
33
|
+
`**@${node_id} ${node.name}** — ${formatNumber(node.edge_count)} total references, showing ${edges.length}`,
|
|
34
|
+
'',
|
|
35
|
+
];
|
|
36
|
+
const headers = [
|
|
37
|
+
'Edge Name',
|
|
38
|
+
'Edge Type',
|
|
39
|
+
'Target ID',
|
|
40
|
+
'Target Name',
|
|
41
|
+
'Target Type',
|
|
42
|
+
'Retained',
|
|
43
|
+
];
|
|
44
|
+
const rightCols = new Set([5]);
|
|
45
|
+
const rows = edges.map(e => [
|
|
46
|
+
String(e.name_or_index),
|
|
47
|
+
e.type,
|
|
48
|
+
`@${e.toNode.id}`,
|
|
49
|
+
e.toNode.name,
|
|
50
|
+
e.toNode.type,
|
|
51
|
+
formatBytes(e.toNode.retainedSize),
|
|
52
|
+
]);
|
|
53
|
+
lines.push(markdownTable(headers, rows, rightCols));
|
|
54
|
+
return textResult(lines.join('\n'));
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return errorResult(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=get-references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-references.js","sourceRoot":"","sources":["../../src/tools/get-references.ts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AC;YAEF,MAAM,OAAO,GAAG;gBACd,WAAW;gBACX,WAAW;gBACX,WAAW;gBACX,aAAa;gBACb,aAAa;gBACb,UAAU;aACX,CAAC;YACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1B,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;gBACvB,CAAC,CAAC,IAAI;gBACN,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE;gBACjB,CAAC,CAAC,MAAM,CAAC,IAAI;gBACb,CAAC,CAAC,MAAM,CAAC,IAAI;gBACb,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;aACnC,CAAC,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;YAEpD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
11
|
+
export declare function registerGetReferrers(server: McpServer): void;
|
|
12
|
+
//# sourceMappingURL=get-referrers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-referrers.d.ts","sourceRoot":"","sources":["../../src/tools/get-referrers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAWvE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAuD5D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { getSnapshot } from '../heap-state.js';
|
|
12
|
+
import { formatBytes, formatNumber, markdownTable, errorResult, textResult, } from '../utils.js';
|
|
13
|
+
export function registerGetReferrers(server) {
|
|
14
|
+
server.tool('memlab_get_referrers', 'Get incoming edges (referrers) to a heap node, sorted by source retained size. Shows what objects hold references to this node.', {
|
|
15
|
+
node_id: z.number().describe('The numeric ID of the heap node'),
|
|
16
|
+
limit: z
|
|
17
|
+
.number()
|
|
18
|
+
.optional()
|
|
19
|
+
.default(30)
|
|
20
|
+
.describe('Maximum number of referrers to return (default 30)'),
|
|
21
|
+
}, async ({ node_id, limit }) => {
|
|
22
|
+
try {
|
|
23
|
+
const snapshot = getSnapshot();
|
|
24
|
+
const node = snapshot.getNodeById(node_id);
|
|
25
|
+
if (!node) {
|
|
26
|
+
return errorResult(`Node with id ${node_id} not found`);
|
|
27
|
+
}
|
|
28
|
+
const edges = node.referrers
|
|
29
|
+
.slice()
|
|
30
|
+
.sort((a, b) => b.fromNode.retainedSize - a.fromNode.retainedSize)
|
|
31
|
+
.slice(0, limit);
|
|
32
|
+
const lines = [
|
|
33
|
+
`**@${node_id} ${node.name}** — ${formatNumber(node.numOfReferrers)} total referrers, showing ${edges.length}`,
|
|
34
|
+
'',
|
|
35
|
+
];
|
|
36
|
+
const headers = [
|
|
37
|
+
'Source ID',
|
|
38
|
+
'Source Name',
|
|
39
|
+
'Source Type',
|
|
40
|
+
'Edge Name',
|
|
41
|
+
'Edge Type',
|
|
42
|
+
'Retained',
|
|
43
|
+
];
|
|
44
|
+
const rightCols = new Set([5]);
|
|
45
|
+
const rows = edges.map(e => [
|
|
46
|
+
`@${e.fromNode.id}`,
|
|
47
|
+
e.fromNode.name,
|
|
48
|
+
e.fromNode.type,
|
|
49
|
+
String(e.name_or_index),
|
|
50
|
+
e.type,
|
|
51
|
+
formatBytes(e.fromNode.retainedSize),
|
|
52
|
+
]);
|
|
53
|
+
lines.push(markdownTable(headers, rows, rightCols));
|
|
54
|
+
return textResult(lines.join('\n'));
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return errorResult(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=get-referrers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-referrers.js","sourceRoot":"","sources":["../../src/tools/get-referrers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,oBAAoB,CAAC,MAAiB;IACpD,MAAM,CAAC,IAAI,CACT,sBAAsB,EACtB,iIAAiI,EACjI;QACE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;QAC/D,KAAK,EAAE,CAAC;aACL,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,OAAO,CAAC,EAAE,CAAC;aACX,QAAQ,C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AC;aACrC,CAAC,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;YAEpD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
11
|
+
export declare function registerGlobalVariables(server: McpServer): void;
|
|
12
|
+
//# sourceMappingURL=global-variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-variables.d.ts","sourceRoot":"","sources":["../../src/tools/global-variables.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAgQvE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAmF/D"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { getSnapshot } from '../heap-state.js';
|
|
12
|
+
import { formatBytes, markdownTable, errorResult, textResult } from '../utils.js';
|
|
13
|
+
// Common built-in Window properties that should be excluded.
|
|
14
|
+
// This is a subset of the ~780 known browser globals from MemLab's BuiltInGlobalVariables.
|
|
15
|
+
const BUILTIN_GLOBALS = new Set([
|
|
16
|
+
// Core
|
|
17
|
+
'undefined',
|
|
18
|
+
'NaN',
|
|
19
|
+
'Infinity',
|
|
20
|
+
'globalThis',
|
|
21
|
+
'self',
|
|
22
|
+
'window',
|
|
23
|
+
// DOM
|
|
24
|
+
'document',
|
|
25
|
+
'navigator',
|
|
26
|
+
'location',
|
|
27
|
+
'history',
|
|
28
|
+
'screen',
|
|
29
|
+
'performance',
|
|
30
|
+
'localStorage',
|
|
31
|
+
'sessionStorage',
|
|
32
|
+
'caches',
|
|
33
|
+
'crypto',
|
|
34
|
+
'indexedDB',
|
|
35
|
+
'console',
|
|
36
|
+
'alert',
|
|
37
|
+
'confirm',
|
|
38
|
+
'prompt',
|
|
39
|
+
'close',
|
|
40
|
+
'open',
|
|
41
|
+
'print',
|
|
42
|
+
'top',
|
|
43
|
+
'parent',
|
|
44
|
+
'frames',
|
|
45
|
+
'frameElement',
|
|
46
|
+
'opener',
|
|
47
|
+
'devicePixelRatio',
|
|
48
|
+
'innerHeight',
|
|
49
|
+
'innerWidth',
|
|
50
|
+
'outerHeight',
|
|
51
|
+
'outerWidth',
|
|
52
|
+
'scrollX',
|
|
53
|
+
'scrollY',
|
|
54
|
+
'pageXOffset',
|
|
55
|
+
'pageYOffset',
|
|
56
|
+
'screenX',
|
|
57
|
+
'screenY',
|
|
58
|
+
'screenLeft',
|
|
59
|
+
'screenTop',
|
|
60
|
+
'visualViewport',
|
|
61
|
+
'styleMedia',
|
|
62
|
+
// Events
|
|
63
|
+
'addEventListener',
|
|
64
|
+
'removeEventListener',
|
|
65
|
+
'dispatchEvent',
|
|
66
|
+
'onclick',
|
|
67
|
+
'onload',
|
|
68
|
+
'onerror',
|
|
69
|
+
'onmessage',
|
|
70
|
+
'onresize',
|
|
71
|
+
'onscroll',
|
|
72
|
+
'onbeforeunload',
|
|
73
|
+
'onunload',
|
|
74
|
+
'onhashchange',
|
|
75
|
+
'onpopstate',
|
|
76
|
+
'onfocus',
|
|
77
|
+
'onblur',
|
|
78
|
+
'onkeydown',
|
|
79
|
+
'onkeyup',
|
|
80
|
+
'onkeypress',
|
|
81
|
+
'onmousedown',
|
|
82
|
+
'onmouseup',
|
|
83
|
+
'onmousemove',
|
|
84
|
+
'onmouseenter',
|
|
85
|
+
'onmouseleave',
|
|
86
|
+
'ontouchstart',
|
|
87
|
+
'ontouchend',
|
|
88
|
+
'ontouchmove',
|
|
89
|
+
'ontouchcancel',
|
|
90
|
+
'onanimationend',
|
|
91
|
+
'onanimationstart',
|
|
92
|
+
'onanimationiteration',
|
|
93
|
+
'ontransitionend',
|
|
94
|
+
'onpointerdown',
|
|
95
|
+
'onpointerup',
|
|
96
|
+
'onpointermove',
|
|
97
|
+
// Timers
|
|
98
|
+
'setTimeout',
|
|
99
|
+
'clearTimeout',
|
|
100
|
+
'setInterval',
|
|
101
|
+
'clearInterval',
|
|
102
|
+
'requestAnimationFrame',
|
|
103
|
+
'cancelAnimationFrame',
|
|
104
|
+
'requestIdleCallback',
|
|
105
|
+
'cancelIdleCallback',
|
|
106
|
+
// Fetch / Network
|
|
107
|
+
'fetch',
|
|
108
|
+
'XMLHttpRequest',
|
|
109
|
+
'WebSocket',
|
|
110
|
+
'EventSource',
|
|
111
|
+
'Request',
|
|
112
|
+
'Response',
|
|
113
|
+
'Headers',
|
|
114
|
+
'URL',
|
|
115
|
+
'URLSearchParams',
|
|
116
|
+
'AbortController',
|
|
117
|
+
'AbortSignal',
|
|
118
|
+
// Workers
|
|
119
|
+
'Worker',
|
|
120
|
+
'SharedWorker',
|
|
121
|
+
'ServiceWorker',
|
|
122
|
+
'BroadcastChannel',
|
|
123
|
+
'MessageChannel',
|
|
124
|
+
// Media
|
|
125
|
+
'Image',
|
|
126
|
+
'Audio',
|
|
127
|
+
'MediaSource',
|
|
128
|
+
'MediaStream',
|
|
129
|
+
'MediaRecorder',
|
|
130
|
+
'AudioContext',
|
|
131
|
+
'OfflineAudioContext',
|
|
132
|
+
'SpeechSynthesis',
|
|
133
|
+
// Constructors
|
|
134
|
+
'Object',
|
|
135
|
+
'Function',
|
|
136
|
+
'Array',
|
|
137
|
+
'Number',
|
|
138
|
+
'String',
|
|
139
|
+
'Boolean',
|
|
140
|
+
'Symbol',
|
|
141
|
+
'Date',
|
|
142
|
+
'RegExp',
|
|
143
|
+
'Error',
|
|
144
|
+
'TypeError',
|
|
145
|
+
'RangeError',
|
|
146
|
+
'SyntaxError',
|
|
147
|
+
'ReferenceError',
|
|
148
|
+
'URIError',
|
|
149
|
+
'EvalError',
|
|
150
|
+
'Map',
|
|
151
|
+
'Set',
|
|
152
|
+
'WeakMap',
|
|
153
|
+
'WeakSet',
|
|
154
|
+
'WeakRef',
|
|
155
|
+
'FinalizationRegistry',
|
|
156
|
+
'Promise',
|
|
157
|
+
'Proxy',
|
|
158
|
+
'Reflect',
|
|
159
|
+
'ArrayBuffer',
|
|
160
|
+
'SharedArrayBuffer',
|
|
161
|
+
'DataView',
|
|
162
|
+
'Int8Array',
|
|
163
|
+
'Uint8Array',
|
|
164
|
+
'Uint8ClampedArray',
|
|
165
|
+
'Int16Array',
|
|
166
|
+
'Uint16Array',
|
|
167
|
+
'Int32Array',
|
|
168
|
+
'Uint32Array',
|
|
169
|
+
'Float32Array',
|
|
170
|
+
'Float64Array',
|
|
171
|
+
'BigInt64Array',
|
|
172
|
+
'BigUint64Array',
|
|
173
|
+
'JSON',
|
|
174
|
+
'Math',
|
|
175
|
+
'Intl',
|
|
176
|
+
'Atomics',
|
|
177
|
+
'BigInt',
|
|
178
|
+
'TextEncoder',
|
|
179
|
+
'TextDecoder',
|
|
180
|
+
'Blob',
|
|
181
|
+
'File',
|
|
182
|
+
'FileReader',
|
|
183
|
+
'FileList',
|
|
184
|
+
'FormData',
|
|
185
|
+
'ReadableStream',
|
|
186
|
+
'WritableStream',
|
|
187
|
+
'TransformStream',
|
|
188
|
+
'CompressionStream',
|
|
189
|
+
'DecompressionStream',
|
|
190
|
+
'MutationObserver',
|
|
191
|
+
'IntersectionObserver',
|
|
192
|
+
'ResizeObserver',
|
|
193
|
+
'PerformanceObserver',
|
|
194
|
+
'CustomEvent',
|
|
195
|
+
'Event',
|
|
196
|
+
'EventTarget',
|
|
197
|
+
// DOM constructors
|
|
198
|
+
'Element',
|
|
199
|
+
'HTMLElement',
|
|
200
|
+
'HTMLDivElement',
|
|
201
|
+
'HTMLSpanElement',
|
|
202
|
+
'HTMLInputElement',
|
|
203
|
+
'HTMLButtonElement',
|
|
204
|
+
'HTMLFormElement',
|
|
205
|
+
'HTMLAnchorElement',
|
|
206
|
+
'HTMLImageElement',
|
|
207
|
+
'HTMLCanvasElement',
|
|
208
|
+
'HTMLVideoElement',
|
|
209
|
+
'HTMLAudioElement',
|
|
210
|
+
'HTMLScriptElement',
|
|
211
|
+
'HTMLStyleElement',
|
|
212
|
+
'HTMLLinkElement',
|
|
213
|
+
'HTMLMetaElement',
|
|
214
|
+
'HTMLHeadElement',
|
|
215
|
+
'HTMLBodyElement',
|
|
216
|
+
'HTMLIFrameElement',
|
|
217
|
+
'HTMLSelectElement',
|
|
218
|
+
'HTMLOptionElement',
|
|
219
|
+
'HTMLTextAreaElement',
|
|
220
|
+
'HTMLTableElement',
|
|
221
|
+
'HTMLTableRowElement',
|
|
222
|
+
'HTMLTableCellElement',
|
|
223
|
+
'Document',
|
|
224
|
+
'DocumentFragment',
|
|
225
|
+
'Node',
|
|
226
|
+
'NodeList',
|
|
227
|
+
'NamedNodeMap',
|
|
228
|
+
'DOMParser',
|
|
229
|
+
'XMLSerializer',
|
|
230
|
+
'Range',
|
|
231
|
+
'Selection',
|
|
232
|
+
'TreeWalker',
|
|
233
|
+
'SVGElement',
|
|
234
|
+
'SVGSVGElement',
|
|
235
|
+
// CSS
|
|
236
|
+
'CSS',
|
|
237
|
+
'CSSStyleSheet',
|
|
238
|
+
'CSSRule',
|
|
239
|
+
'CSSStyleDeclaration',
|
|
240
|
+
'getComputedStyle',
|
|
241
|
+
'matchMedia',
|
|
242
|
+
// Encoding
|
|
243
|
+
'atob',
|
|
244
|
+
'btoa',
|
|
245
|
+
'encodeURI',
|
|
246
|
+
'decodeURI',
|
|
247
|
+
'encodeURIComponent',
|
|
248
|
+
'decodeURIComponent',
|
|
249
|
+
'escape',
|
|
250
|
+
'unescape',
|
|
251
|
+
'eval',
|
|
252
|
+
'isFinite',
|
|
253
|
+
'isNaN',
|
|
254
|
+
'parseInt',
|
|
255
|
+
'parseFloat',
|
|
256
|
+
// Misc
|
|
257
|
+
'queueMicrotask',
|
|
258
|
+
'structuredClone',
|
|
259
|
+
'reportError',
|
|
260
|
+
'createImageBitmap',
|
|
261
|
+
'postMessage',
|
|
262
|
+
]);
|
|
263
|
+
export function registerGlobalVariables(server) {
|
|
264
|
+
server.tool('memlab_global_variables', 'Find non-built-in global variables on the Window object, sorted by retained size. These are application-specific globals that may indicate memory issues.', {
|
|
265
|
+
limit: z
|
|
266
|
+
.number()
|
|
267
|
+
.optional()
|
|
268
|
+
.default(20)
|
|
269
|
+
.describe('Maximum number of results (default 20)'),
|
|
270
|
+
}, async ({ limit }) => {
|
|
271
|
+
try {
|
|
272
|
+
const snapshot = getSnapshot();
|
|
273
|
+
const globals = [];
|
|
274
|
+
snapshot.nodes.forEach(node => {
|
|
275
|
+
if (!node.name.startsWith('Window '))
|
|
276
|
+
return;
|
|
277
|
+
for (const edge of node.references) {
|
|
278
|
+
const edgeName = String(edge.name_or_index);
|
|
279
|
+
// Skip built-in globals
|
|
280
|
+
if (BUILTIN_GLOBALS.has(edgeName))
|
|
281
|
+
continue;
|
|
282
|
+
// Skip internal/hidden edges
|
|
283
|
+
if (edge.type === 'hidden' || edge.type === 'internal')
|
|
284
|
+
continue;
|
|
285
|
+
// Skip symbol edges
|
|
286
|
+
if (edgeName.startsWith('<symbol>'))
|
|
287
|
+
continue;
|
|
288
|
+
// Skip non-inspectable target types
|
|
289
|
+
const target = edge.toNode;
|
|
290
|
+
if (target.type === 'hidden' ||
|
|
291
|
+
target.type === 'array' ||
|
|
292
|
+
target.type === 'number')
|
|
293
|
+
continue;
|
|
294
|
+
globals.push({
|
|
295
|
+
name: edgeName,
|
|
296
|
+
target_id: target.id,
|
|
297
|
+
target_name: target.name,
|
|
298
|
+
target_type: target.type,
|
|
299
|
+
retained_size: target.retainedSize,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
// Sort by retained size descending
|
|
304
|
+
globals.sort((a, b) => b.retained_size - a.retained_size);
|
|
305
|
+
const topGlobals = globals.slice(0, limit);
|
|
306
|
+
if (topGlobals.length === 0) {
|
|
307
|
+
return textResult('No non-built-in global variables found.');
|
|
308
|
+
}
|
|
309
|
+
const headers = [
|
|
310
|
+
'Variable',
|
|
311
|
+
'Target ID',
|
|
312
|
+
'Target Name',
|
|
313
|
+
'Target Type',
|
|
314
|
+
'Retained',
|
|
315
|
+
];
|
|
316
|
+
const rightCols = new Set([4]);
|
|
317
|
+
const rows = topGlobals.map(g => [
|
|
318
|
+
g.name,
|
|
319
|
+
`@${g.target_id}`,
|
|
320
|
+
g.target_name,
|
|
321
|
+
g.target_type,
|
|
322
|
+
formatBytes(g.retained_size),
|
|
323
|
+
]);
|
|
324
|
+
return textResult(`Global variables (${topGlobals.length} found)\n\n${markdownTable(headers, rows, rightCols)}`);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
return errorResult(err);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=global-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-variables.js","sourceRoot":"","sources":["../../src/tools/global-variables.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,O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AC;YACD,MAAM,OAAO,GAAG;gBACd,UAAU;gBACV,WAAW;gBACX,aAAa;gBACb,aAAa;gBACb,UAAU;aACX,CAAC;YACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/B,CAAC,CAAC,IAAI;gBACN,IAAI,CAAC,CAAC,SAAS,EAAE;gBACjB,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,WAAW;gBACb,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC;aAC7B,CAAC,CAAC;YACH,OAAO,UAAU,CACf,qBAAqB,UAAU,CAAC,MAAM,cAAc,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAC9F,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
* @oncall memory_lab
|
|
9
|
+
*/
|
|
10
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
11
|
+
export declare function registerLargestObjects(server: McpServer): void;
|
|
12
|
+
//# sourceMappingURL=largest-objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"largest-objects.d.ts","sourceRoot":"","sources":["../../src/tools/largest-objects.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAYvE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA4B9D"}
|