mcinsight-mcp-server 0.1.0-beta.2 → 0.1.0-beta.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.
Files changed (99) hide show
  1. package/README.md +40 -126
  2. package/dist/api/endpoints.js +157 -0
  3. package/dist/api/errors.js +35 -0
  4. package/dist/api/result.js +84 -0
  5. package/dist/api/types.js +9 -0
  6. package/dist/bytecode/classFile.js +172 -0
  7. package/dist/bytecode/constantPool.js +150 -0
  8. package/dist/bytecode/opcodes.js +102 -0
  9. package/dist/client/mcClient.js +109 -79
  10. package/dist/data/advancements.js +18 -0
  11. package/dist/data/datamaps.js +58 -0
  12. package/dist/data/guides.js +30 -0
  13. package/dist/data/loot.js +84 -0
  14. package/dist/data/recipes.js +166 -0
  15. package/dist/data/registry.js +45 -0
  16. package/dist/data/trades.js +21 -0
  17. package/dist/data/worldState.js +42 -0
  18. package/dist/data/worldgen.js +65 -0
  19. package/dist/decompiler/jarInspector.js +73 -1082
  20. package/dist/decompiler/vineflower.js +191 -0
  21. package/dist/index.js +98 -26
  22. package/dist/jar/concurrency.js +31 -0
  23. package/dist/jar/index.js +220 -0
  24. package/dist/jar/packScripts.js +130 -0
  25. package/dist/jar/resolve.js +137 -0
  26. package/dist/jar/search.js +181 -0
  27. package/dist/jar/trace.js +222 -0
  28. package/dist/metadata/modMetadata.js +67 -0
  29. package/dist/parsers/modParsers/ae2Parser.js +111 -20
  30. package/dist/parsers/modParsers/arsNouveauParser.js +132 -19
  31. package/dist/parsers/modParsers/createParser.js +121 -22
  32. package/dist/parsers/modParsers/farmersDelightParser.js +25 -15
  33. package/dist/parsers/modParsers/index.js +9 -7
  34. package/dist/parsers/modParsers/mekanismParser.js +126 -38
  35. package/dist/parsers/modParsers/oritechParser.js +50 -24
  36. package/dist/parsers/modParsers/tofucraftParser.js +40 -19
  37. package/dist/parsers/modParsers/types.js +155 -30
  38. package/dist/parsers/modVersion.js +22 -19
  39. package/dist/parsers/nativeParsers.js +446 -94
  40. package/dist/parsers/retention.js +31 -0
  41. package/dist/parsers/shared.js +33 -0
  42. package/dist/server.js +4 -48
  43. package/dist/tools/codeTools.js +63 -38
  44. package/dist/tools/guideTools.js +24 -15
  45. package/dist/tools/helpers.js +38 -55
  46. package/dist/tools/mechanicsTools.js +270 -228
  47. package/dist/tools/registryTools.js +42 -27
  48. package/dist/tools/result.js +21 -0
  49. package/dist/tools/worldStateTools.js +15 -22
  50. package/dist/transports/http.js +34 -14
  51. package/dist/transports/stdio.js +7 -3
  52. package/dist/version.js +17 -0
  53. package/package.json +7 -6
  54. package/dist/client/mcClient.d.ts +0 -68
  55. package/dist/client/mcClient.js.map +0 -1
  56. package/dist/decompiler/jarInspector.d.ts +0 -139
  57. package/dist/decompiler/jarInspector.js.map +0 -1
  58. package/dist/index.d.ts +0 -2
  59. package/dist/index.js.map +0 -1
  60. package/dist/parsers/modParsers/ae2Parser.d.ts +0 -2
  61. package/dist/parsers/modParsers/ae2Parser.js.map +0 -1
  62. package/dist/parsers/modParsers/arsNouveauParser.d.ts +0 -2
  63. package/dist/parsers/modParsers/arsNouveauParser.js.map +0 -1
  64. package/dist/parsers/modParsers/createParser.d.ts +0 -2
  65. package/dist/parsers/modParsers/createParser.js.map +0 -1
  66. package/dist/parsers/modParsers/farmersDelightParser.d.ts +0 -2
  67. package/dist/parsers/modParsers/farmersDelightParser.js.map +0 -1
  68. package/dist/parsers/modParsers/index.d.ts +0 -24
  69. package/dist/parsers/modParsers/index.js.map +0 -1
  70. package/dist/parsers/modParsers/mekanismParser.d.ts +0 -2
  71. package/dist/parsers/modParsers/mekanismParser.js.map +0 -1
  72. package/dist/parsers/modParsers/oritechParser.d.ts +0 -2
  73. package/dist/parsers/modParsers/oritechParser.js.map +0 -1
  74. package/dist/parsers/modParsers/tofucraftParser.d.ts +0 -2
  75. package/dist/parsers/modParsers/tofucraftParser.js.map +0 -1
  76. package/dist/parsers/modParsers/types.d.ts +0 -34
  77. package/dist/parsers/modParsers/types.js.map +0 -1
  78. package/dist/parsers/modVersion.d.ts +0 -3
  79. package/dist/parsers/modVersion.js.map +0 -1
  80. package/dist/parsers/nativeParsers.d.ts +0 -83
  81. package/dist/parsers/nativeParsers.js.map +0 -1
  82. package/dist/server.d.ts +0 -10
  83. package/dist/server.js.map +0 -1
  84. package/dist/tools/codeTools.d.ts +0 -7
  85. package/dist/tools/codeTools.js.map +0 -1
  86. package/dist/tools/guideTools.d.ts +0 -3
  87. package/dist/tools/guideTools.js.map +0 -1
  88. package/dist/tools/helpers.d.ts +0 -58
  89. package/dist/tools/helpers.js.map +0 -1
  90. package/dist/tools/mechanicsTools.d.ts +0 -3
  91. package/dist/tools/mechanicsTools.js.map +0 -1
  92. package/dist/tools/registryTools.d.ts +0 -3
  93. package/dist/tools/registryTools.js.map +0 -1
  94. package/dist/tools/worldStateTools.d.ts +0 -3
  95. package/dist/tools/worldStateTools.js.map +0 -1
  96. package/dist/transports/http.d.ts +0 -9
  97. package/dist/transports/http.js.map +0 -1
  98. package/dist/transports/stdio.d.ts +0 -2
  99. package/dist/transports/stdio.js.map +0 -1
package/README.md CHANGED
@@ -2,74 +2,54 @@
2
2
 
3
3
  **English** | [日本語](README.ja.md)
4
4
 
5
- [![CI](https://github.com/minetake01/McInsightMCP/actions/workflows/ci.yml/badge.svg)](https://github.com/minetake01/McInsightMCP/actions/workflows/ci.yml)
6
- [![Release](https://img.shields.io/github/v/release/minetake01/McInsightMCP?include_prereleases&label=release)](https://github.com/minetake01/McInsightMCP/releases)
7
- [![Status: Beta](https://img.shields.io/badge/Status-Beta-yellow.svg)](CHANGELOG.md)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
9
- [![Minecraft](https://img.shields.io/badge/Minecraft-NeoForge%20%7C%20Fabric-62B47A.svg)](https://github.com/minetake01/McInsightMCP/releases)
10
-
11
5
  **Ask your AI assistant about the Minecraft world you are actually playing.**
12
6
 
13
- McInsightMCP connects MCP-compatible AI assistants (Claude Desktop, Cursor, Claude Code, VS Code, and others) directly to your running **Minecraft** game. Instead of guessing from outdated wikis, your AI can look up real recipes in your modpack (including KubeJS and datapack tweaks), see what block or machine you are looking at, check your inventory, read in-game guidebooks and quests, and inspect how unfamiliar mods actually work.
14
-
15
- > [!NOTE]
16
- > **Beta Release (`0.1.0-beta.2`)**: McInsightMCP is currently in beta. MCP tool schemas, response formats, and configuration options may change before `1.0.0`. Bug reports and feedback are welcome via [GitHub Issues](https://github.com/minetake01/McInsightMCP/issues).
17
-
18
- ---
7
+ McInsightMCP connects MCP-compatible AI assistants (Claude Desktop, Cursor, Claude Code, VS Code, and others) directly to your running **Minecraft** game. Instead of guessing from outdated wikis, your AI can check real recipes in your modpack (including KubeJS and datapack tweaks), inspect the block or machine you are looking at, check your inventory, read in-game guidebooks and quests, and inspect mod files when documentation is missing.
19
8
 
20
- ## Why Use McInsightMCP?
9
+ > **Beta:** McInsightMCP is currently in beta, so configuration options and internal tool behavior may change before `1.0.0`. Bug reports and feedback are welcome on [GitHub Issues](https://github.com/minetake01/McInsightMCP/issues).
21
10
 
22
- - **Accurate to Your Modpack**: Reads live recipes, ore generation, loot tables, villager trades, advancements, and KubeJS/datapack overrides straight from the running game.
23
- - **100% Read-Only & Safe**: Never breaks blocks, edits your world, moves your player, or sends commands. It only observes.
24
- - **Local-Only by Default**: Runs on `127.0.0.1` on your machine — no external servers, no telemetry, and no screen capture.
25
- - **Client-Friendly Multiplayer**: Works on multiplayer servers even when installed only on your client (recipes, inventory, raycast target, and guides). In singleplayer — or when also installed on the server — it additionally reads full machine/chest NBT and dynamic loot tables.
26
- - **Works With Any Modpack**: Automatically integrates with optional mods when installed, and can even inspect mod resources or decompile mod classes when documentation is missing.
11
+ ## What You Can Ask
27
12
 
28
- ---
13
+ - *"How do I craft `mekanism:atomic_alloy` in this modpack, and do I have the materials in my inventory?"*
14
+ - *"What is this machine I'm looking at, and why isn't it running?"*
15
+ - *"At what Y-level and in which biomes does osmium or platinum ore generate in this pack?"*
16
+ - *"Search Patchouli, FTB Quests, Create Ponder, or GuideME for how to automate this resource."*
17
+ - *"There's no wiki page for this modded item—check the mod itself and explain how it works."*
29
18
 
30
- ## What You Can Ask Your AI
19
+ ## Features
31
20
 
32
- - *"How do I craft or obtain `mekanism:atomic_alloy` in this pack, and do I already have the materials in my inventory?"*
33
- - *"What is this machine I'm looking at right now, and why isn't it running?"*
34
- - *"At what Y-level and in which biomes does this modpack's osmium or platinum ore generate?"*
35
- - *"Search the Patchouli / FTB Quests / Create Ponder / GuideME docs for how to automate this resource."*
36
- - *"I can't find any wiki page for this modded item — check the mod itself and explain how the mechanic works."*
21
+ - **Accurate to Your Modpack**: Reads live recipes, KubeJS and datapack overrides, ore generation, loot tables, villager trades, and advancements straight from your running game.
22
+ - **Read-Only and Safe**: Never breaks or places blocks, edits your world, moves your player, or runs commands.
23
+ - **Local-Only and Private**: Communicates strictly over `127.0.0.1` on your machine—no external servers, no telemetry, and no screen capture.
24
+ - **Singleplayer and Multiplayer**: Works client-only on multiplayer servers for recipes, inventory, what you are looking at, and guides. In singleplayer—or when the server also has McInsight installed—it also reads server-side data such as ore/world generation, loot tables, villager trades, advancement progress, NeoForge data maps, and block-entity contents (chests and machines).
25
+ - **Works With Any Modpack**: Automatically integrates with supported recipe viewers and guide mods, and can inspect mod resources or decompile mod classes when docs are missing.
37
26
 
38
- ---
39
-
40
- ## Requirements & Supported Integrations
27
+ ## Requirements & Mod Support
41
28
 
42
29
  | Component | Requirement |
43
30
  |---|---|
44
- | **Minecraft** | Currently `1.21.1` (Java 21) — see [Releases](https://github.com/minetake01/McInsightMCP/releases) for supported versions |
45
- | **NeoForge** | Standalone — no required mod dependencies |
31
+ | **Minecraft** | `1.21.1` (Java 21), `26.1.2`, `26.3` (Java 25) |
32
+ | **NeoForge** | Standalone (no required dependencies) |
46
33
  | **Fabric** | Requires [Fabric API](https://modrinth.com/mod/fabric-api) |
47
- | **MCP Server** | [Node.js](https://nodejs.org/) `>= 20` |
48
-
49
- ### Optional In-Game Integrations (Auto-Detected)
50
- - **JEI** (categories, catalysts, and JEI item info pages)
51
- - **In-Game Guides & Quests**: Patchouli, GuideME, FTB Quests, Create Ponder, Oracle Index, and mod language files
34
+ | **MCP Server** | [Node.js](https://nodejs.org/) `22.12+` |
52
35
 
53
- ### Built-In Mod Recipe Formatting
54
- Works with **any** modpack via raw recipe data, and includes dedicated structured recipe formatting for **Create**, **Mekanism**, **Applied Energistics 2**, **Oritech**, **Farmer's Delight**, **Ars Nouveau**, and **TofuCraftReload**.
36
+ ### Optional Integrations (Auto-Detected)
55
37
 
56
- ---
38
+ - **Recipe Viewers**: JEI, REI, and EMI (`1.21.1` only)
39
+ - **Guides & Quests**: Patchouli, GuideME, FTB Quests, Create Ponder, Oracle Index, and mod language files
40
+ - **Enhanced Recipe Formatting**: Works with any modpack via raw recipe data, with dedicated structured formatting for Create, Mekanism, Applied Energistics 2, Oritech, Farmer's Delight, Ars Nouveau, and TofuCraftReload
57
41
 
58
- ## Quick Start
42
+ ## Setup
59
43
 
60
- ### Step 1: Install the Minecraft Mod
44
+ ### 1. Install the Minecraft Mod
61
45
 
62
- 1. Download the mod JAR for your Minecraft version and loader from [GitHub Releases](https://github.com/minetake01/McInsightMCP/releases):
63
- - **NeoForge**: `mcinsight-neoforge-<mc_version>-<version>.jar`
64
- - **Fabric**: `mcinsight-fabric-<mc_version>-<version>.jar` (also make sure **Fabric API** is in `mods/`)
65
- 2. Place the JAR into your Minecraft instance's `mods/` folder.
46
+ 1. Download the mod JAR for your Minecraft version and loader (on Fabric, also install [Fabric API](https://modrinth.com/mod/fabric-api)).
47
+ 2. Place it in your Minecraft instance's `mods/` folder.
66
48
  3. Launch Minecraft and load into a world.
67
49
 
68
- ### Step 2: Connect Your AI Client
69
-
70
- #### Option A: `stdio` (Recommended)
50
+ ### 2. Connect Your AI Client
71
51
 
72
- Recommended for Claude Desktop, Cursor, Claude Code, and VS Code. Add this to your MCP client configuration:
52
+ Add the following to your AI client's MCP configuration (recommended for Claude Desktop, Cursor, Claude Code, and VS Code):
73
53
 
74
54
  ```json
75
55
  {
@@ -82,95 +62,29 @@ Recommended for Claude Desktop, Cursor, Claude Code, and VS Code. Add this to yo
82
62
  }
83
63
  ```
84
64
 
85
- With `pnpm`, you can also use `"command": "pnpx"` and `"args": ["mcinsight-mcp-server@beta", "--stdio"]`.
65
+ The MCP server automatically finds the running mod on `127.0.0.1` ports `25580`–`25599`, so no port setup is needed in normal use.
86
66
 
87
- #### Option B: Streamable HTTP
88
-
89
- Start the server locally:
67
+ If your client prefers Streamable HTTP instead of `stdio`, run the server locally and connect to `http://127.0.0.1:3876/mcp`:
90
68
 
91
69
  ```bash
92
70
  npx -y mcinsight-mcp-server@beta --http --port 3876
93
- # or with pnpm:
94
- pnpx mcinsight-mcp-server@beta --http --port 3876
95
71
  ```
96
72
 
97
- Then point your MCP client to `http://127.0.0.1:3876/mcp`.
98
-
99
- #### Manual / Offline Setup (GitHub Releases)
100
-
101
- You can also download and extract `mcinsight-mcp-server-<version>` from [GitHub Releases](https://github.com/minetake01/McInsightMCP/releases), install runtime dependencies inside the extracted folder (`pnpm install --prod` or `npm install --omit=dev`), and run `node /path/to/mcinsight-mcp-server/dist/index.js --stdio` (or build from source — see below).
102
-
103
- > **Tip**: By default, the MCP server automatically discovers a running McInsight mod on `127.0.0.1` ports `25580..25599` — no manual port configuration needed.
104
-
105
- ---
73
+ Pre-packaged offline archives of the MCP server are also available on [GitHub Releases](https://github.com/minetake01/McInsightMCP/releases).
106
74
 
107
75
  ## Optional Configuration
108
76
 
109
- ### Minecraft Mod (`config/mcinsight.json`)
110
-
111
- Generated automatically on first launch:
77
+ Most users do not need to change any settings.
112
78
 
113
- | Key | Default | Description |
114
- |---|---|---|
115
- | `enabled` | `true` | Enable or disable the local HTTP API |
116
- | `port` | `25580` | Starting loopback port to bind (`1024..65535`) |
117
- | `portRangeSize` | `20` | Number of consecutive ports to try if the port is busy (`1..50`) |
118
- | `authToken` | `""` | Optional Bearer token required for API requests |
119
- | `maxScanRadius` | `16` | Maximum radius for nearby area scans (`1..32`) |
120
- | `maxRecipeResults` | `100` | Maximum recipes returned per query (`1..500`) |
121
-
122
- ### MCP Server CLI Flags & Environment Variables
123
-
124
- | CLI Flag | Environment Variable | Purpose |
125
- |---|---|---|
126
- | `--stdio` | — | Run over stdio (default) |
127
- | `--http` | — | Run as a local Streamable HTTP server |
128
- | `--port <port>` | `MCP_PORT` | HTTP server port (default `3876`) |
129
- | `--mc-url <url>` | `MCINSIGHT_URL` | Explicit mod URL (skips port auto-discovery) |
130
- | `--token <token>` | `MCINSIGHT_TOKEN` | Bearer token matching `authToken` in `mcinsight.json` |
131
- | `--mods-dir <path>` | `MCINSIGHT_MODS_DIR` | Mods folder path for offline JAR inspection |
132
- | `--game-dir <path>` | `MCINSIGHT_GAME_DIR` | Game folder path for offline KubeJS / FTB Quests scanning |
133
- | `--tools-dir <path>` | `MCINSIGHT_TOOLS_DIR` | Cache directory for downloaded decompiler tools (Vineflower) |
134
-
135
- ---
136
-
137
- ## Available AI Tools
138
-
139
- McInsightMCP exposes 11 tools to your AI assistant:
140
-
141
- - **World & Player**: `mc_status`, `mc_player_state`, `mc_observe_world` (what you are looking at or nearby blocks/entities)
142
- - **Items & Blocks**: `mc_search_registry`, `mc_inspect` (block properties, tags, JEI info)
143
- - **Progression & Crafting**: `mc_query_item_flow`, `mc_query_recipes`, `mc_query_world_data` (worldgen, loot tables, trades, NeoForge data maps), `mc_query_advancements`
144
- - **Guides & Mod Internals**: `mc_guides` (Patchouli, GuideME, FTB Quests, Ponder, Oracle Index, lang), `mc_inspect_code` (resource/script search & Java class inspection)
145
-
146
- ---
147
-
148
- ## Building from Source
149
-
150
- Requires **JDK 21** for the mod and **Node.js >= 20** + **pnpm** for the MCP server.
151
-
152
- ```bash
153
- # 1. Build the NeoForge and Fabric mod JARs
154
- cd mod
155
- ./gradlew :neoforge:build :fabric:build
156
- # Output JARs:
157
- # mod/neoforge/build/libs/mcinsight-neoforge-<mc_version>-0.1.0-beta.2.jar
158
- # mod/fabric/build/libs/mcinsight-fabric-<mc_version>-0.1.0-beta.2.jar
159
-
160
- # 2. Build and test the MCP server
161
- cd ../mcp-server
162
- pnpm install
163
- pnpm typecheck
164
- pnpm build
165
- pnpm test
166
- ```
79
+ - **Minecraft Mod (`config/mcinsight.json`)**: Generated on first launch. Supports `enabled`, `port` (default `25580`), `authToken`, and scan, block-entity sync, and recipe result limits.
80
+ - **MCP Server Flags & Environment Variables**: Use `--mc-url` (`MCINSIGHT_URL`) for a custom mod port, `--token` (`MCINSIGHT_TOKEN`) when `authToken` is set, and `--mods-dir` / `--game-dir` (`MCINSIGHT_MODS_DIR` / `MCINSIGHT_GAME_DIR`) to inspect mod files offline without Minecraft running.
167
81
 
168
- ---
82
+ See [Architecture & Full Configuration](docs/ARCHITECTURE.md#10-configuration-and-limits) for all keys, limits, and flags.
169
83
 
170
- ## Documentation & Links
84
+ ## Links
171
85
 
172
- - [Architecture & Protocol Specification](docs/ARCHITECTURE.md) — Technical details, parser tiers, HTTP endpoints, and threading model
173
- - [Contributing Guide](CONTRIBUTING.md) — Development setup, testing, and how to add mod parsers
174
- - [Security Policy](SECURITY.md) — Read-only & loopback guarantees and vulnerability reporting
175
- - [Changelog](CHANGELOG.md) — Release history
86
+ - [Architecture & Configuration](docs/ARCHITECTURE.md)
87
+ - [Contributing & Building from Source](CONTRIBUTING.md)
88
+ - [Security Policy](SECURITY.md)
89
+ - [Changelog](CHANGELOG.md)
176
90
  - [License (MIT)](LICENSE)
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The endpoint table, mirrored from the mod's `InsightEndpoint`.
3
+ *
4
+ * <p>Every HTTP path, the parameters that endpoint accepts, and its page bounds are declared once
5
+ * here. Tools ask for an endpoint by id and hand over only the parameters that endpoint declares,
6
+ * so a path string cannot drift between two tools and a page limit is never invented locally. When
7
+ * the mod rejects a value the HTTP error reaches the caller unchanged; the bounds here exist to
8
+ * describe the contract, not to shorten a page pre-emptively.
9
+ */
10
+ function endpoint(spec) {
11
+ return spec;
12
+ }
13
+ export const ENDPOINTS = {
14
+ status: endpoint({
15
+ id: 'status',
16
+ path: '/api/v1/status',
17
+ params: ['includeMods'],
18
+ }),
19
+ mods: endpoint({
20
+ id: 'mods',
21
+ path: '/api/v1/mods',
22
+ params: [],
23
+ }),
24
+ metrics: endpoint({
25
+ id: 'metrics',
26
+ path: '/api/v1/metrics',
27
+ params: [],
28
+ }),
29
+ player: endpoint({
30
+ id: 'player',
31
+ path: '/api/v1/player',
32
+ params: [],
33
+ }),
34
+ looking_at: endpoint({
35
+ id: 'looking_at',
36
+ path: '/api/v1/looking-at',
37
+ params: ['maxDistance', 'includeFluids'],
38
+ }),
39
+ scan: endpoint({
40
+ id: 'scan',
41
+ path: '/api/v1/scan',
42
+ params: ['radius', 'filter'],
43
+ }),
44
+ registry_search: endpoint({
45
+ id: 'registry_search',
46
+ path: '/api/v1/registry/search',
47
+ params: ['kind', 'q', 'mod', 'limit', 'offset'],
48
+ defaultLimit: 50,
49
+ maxLimit: 200,
50
+ }),
51
+ registry_inspect: endpoint({
52
+ id: 'registry_inspect',
53
+ path: '/api/v1/registry/inspect',
54
+ params: ['kind', 'id'],
55
+ }),
56
+ registry_tag: endpoint({
57
+ id: 'registry_tag',
58
+ path: '/api/v1/registry/tag',
59
+ params: ['kind', 'id', 'limit', 'offset'],
60
+ defaultLimit: 200,
61
+ maxLimit: 500,
62
+ }),
63
+ recipes_types: endpoint({
64
+ id: 'recipes_types',
65
+ path: '/api/v1/recipes/types',
66
+ params: [],
67
+ }),
68
+ recipes_query: endpoint({
69
+ id: 'recipes_query',
70
+ path: '/api/v1/recipes/query',
71
+ params: ['item', 'role', 'type', 'mod', 'source', 'limit', 'offset'],
72
+ defaultLimit: 40,
73
+ maxLimit: 100,
74
+ }),
75
+ guides_list: endpoint({
76
+ id: 'guides_list',
77
+ path: '/api/v1/guides/list',
78
+ params: ['source', 'mod', 'limit', 'offset'],
79
+ defaultLimit: 50,
80
+ maxLimit: 500,
81
+ }),
82
+ guides_search: endpoint({
83
+ id: 'guides_search',
84
+ path: '/api/v1/guides/search',
85
+ params: ['q', 'source', 'mod', 'lang', 'includeAllLang', 'limit', 'offset'],
86
+ defaultLimit: 20,
87
+ maxLimit: 50,
88
+ }),
89
+ guides_page: endpoint({
90
+ id: 'guides_page',
91
+ path: '/api/v1/guides/page',
92
+ params: ['id'],
93
+ }),
94
+ worldgen_summary: endpoint({
95
+ id: 'worldgen_summary',
96
+ path: '/api/v1/worldgen/summary',
97
+ params: [],
98
+ }),
99
+ worldgen_query: endpoint({
100
+ id: 'worldgen_query',
101
+ path: '/api/v1/worldgen/query',
102
+ params: ['kind', 'q', 'mod', 'searchContent', 'minTemp', 'maxTemp', 'summaryOnly', 'limit', 'offset'],
103
+ defaultLimit: 30,
104
+ maxLimit: 100,
105
+ }),
106
+ loot_query: endpoint({
107
+ id: 'loot_query',
108
+ path: '/api/v1/loot/query',
109
+ params: ['q', 'item', 'mod', 'includeModifiers', 'limit', 'offset'],
110
+ defaultLimit: 30,
111
+ maxLimit: 100,
112
+ }),
113
+ datamaps_query: endpoint({
114
+ id: 'datamaps_query',
115
+ path: '/api/v1/datamaps/query',
116
+ params: ['q', 'item', 'registry', 'mod', 'includeRaw', 'limit', 'offset'],
117
+ defaultLimit: 30,
118
+ maxLimit: 100,
119
+ }),
120
+ trades_query: endpoint({
121
+ id: 'trades_query',
122
+ path: '/api/v1/trades/query',
123
+ params: ['item', 'side', 'q', 'profession', 'mod', 'limit', 'offset'],
124
+ defaultLimit: 40,
125
+ maxLimit: 200,
126
+ }),
127
+ advancements_query: endpoint({
128
+ id: 'advancements_query',
129
+ path: '/api/v1/advancements/query',
130
+ params: ['q', 'mod', 'status', 'includeRecipes', 'limit', 'offset'],
131
+ defaultLimit: 40,
132
+ maxLimit: 200,
133
+ }),
134
+ introspect_class: endpoint({
135
+ id: 'introspect_class',
136
+ path: '/api/v1/introspect/class',
137
+ params: ['name'],
138
+ }),
139
+ };
140
+ export function limitBounds(id) {
141
+ const spec = ENDPOINTS[id];
142
+ if (spec.defaultLimit === undefined || spec.maxLimit === undefined) {
143
+ throw new Error(`Endpoint '${id}' is not paginated; it has no limit bounds.`);
144
+ }
145
+ return { defaultLimit: spec.defaultLimit, maxLimit: spec.maxLimit };
146
+ }
147
+ /**
148
+ * Query one endpoint.
149
+ *
150
+ * <p>This is the only place a path is turned into a URL: tools name an endpoint, not a route. The
151
+ * mod's declared parameter set is what the type allows, so a parameter that endpoint does not accept
152
+ * cannot be sent by accident; a wrong value is answered by the mod with its own error code.
153
+ */
154
+ export async function requestEndpoint(client, id, params = {}) {
155
+ const spec = ENDPOINTS[id];
156
+ return client.get(spec.path, params);
157
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The error catalog mirrored from the mod's `InsightError`.
3
+ *
4
+ * <p>Failures arrive as a non-200 status with {@code {ok:false, code, error}}. The code is the
5
+ * actionable part: it says whether the answer was refused (INVALID_*), absent (NOT_FOUND,
6
+ * DATA_UNAVAILABLE), or deferred (SERVER_MOD_REQUIRED, REMOTE_TIMEOUT), and the tools surface it
7
+ * verbatim instead of inventing their own vocabulary. Keeping the list here means the client and
8
+ * every tool branch on the same strings the mod declares.
9
+ */
10
+ export const INSIGHT_ERROR_CODES = [
11
+ 'INVALID_PARAMETER',
12
+ 'INVALID_QUERY',
13
+ 'INVALID_ID',
14
+ 'INVALID_KIND',
15
+ 'INVALID_SOURCE',
16
+ 'INVALID_CLASS',
17
+ 'UNSUPPORTED_ON_LOADER',
18
+ 'UNSUPPORTED_ENDPOINT',
19
+ 'METHOD_NOT_ALLOWED',
20
+ 'UNAUTHORIZED',
21
+ 'NOT_FOUND',
22
+ 'CLASS_NOT_FOUND',
23
+ 'NO_WORLD',
24
+ 'OUT_OF_RANGE',
25
+ 'RATE_LIMITED',
26
+ 'DATA_UNAVAILABLE',
27
+ 'SERVER_MOD_REQUIRED',
28
+ 'VIEWER_UNAVAILABLE',
29
+ 'REMOTE_TIMEOUT',
30
+ 'REMOTE_ERROR',
31
+ 'INTERNAL_ERROR',
32
+ ];
33
+ export function isInsightErrorCode(value) {
34
+ return INSIGHT_ERROR_CODES.includes(value);
35
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * How a failure or a partially answered query is reported.
3
+ *
4
+ * <p>Two rules, applied by every tool:
5
+ *
6
+ * <ul>
7
+ * <li>a tool result always carries `ok`; a failure is `{ok:false, code, error}` where `code` is the
8
+ * mod's own InsightError code when the mod answered at all, never a paraphrased one;
9
+ * <li>inside a composite answer (`mc_query_item_flow`), a failed part becomes a `missing` entry in
10
+ * the mod's `PartialData` shape, and the answer is marked `partial`. A part that could not be
11
+ * read is never omitted from the answer, because an omitted part reads as "there is nothing".
12
+ * </ul>
13
+ */
14
+ import { McApiError } from '../client/mcClient.js';
15
+ /**
16
+ * A failure detected on the MCP side, before or instead of asking the mod.
17
+ *
18
+ * <p>It carries a code from the same catalog so a caller branches on one vocabulary: `NOT_FOUND` for
19
+ * "the JAR/entry you named is not here", `INVALID_PARAMETER` for a missing required argument. Without
20
+ * this, such failures could only be reported as `INTERNAL_ERROR`, which says "a bug" about what is
21
+ * actually a fact about the request.
22
+ */
23
+ export class ToolError extends Error {
24
+ code;
25
+ constructor(code, message) {
26
+ super(message);
27
+ this.code = code;
28
+ this.name = 'ToolError';
29
+ }
30
+ }
31
+ /**
32
+ * Turns a thrown error into the failure record a tool returns.
33
+ *
34
+ * <p>A mod error keeps its code and message. Anything else (connection refused, discovery timeout,
35
+ * a bug) is reported as MCP-side `CONNECTION_ERROR`/`INTERNAL_ERROR` so the caller can tell "the mod
36
+ * said no" from "we could not ask it".
37
+ */
38
+ export function toFailure(error) {
39
+ if (error instanceof McApiError) {
40
+ return {
41
+ ok: false,
42
+ code: error.code,
43
+ error: error.message,
44
+ ...(error.statusCode > 0 ? { status: error.statusCode } : {}),
45
+ };
46
+ }
47
+ if (error instanceof ToolError) {
48
+ return { ok: false, code: error.code, error: error.message };
49
+ }
50
+ const message = error instanceof Error ? error.message : String(error);
51
+ const code = error instanceof Error && error.name === 'McConnectionError' ? 'CONNECTION_ERROR' : 'INTERNAL_ERROR';
52
+ return { ok: false, code, error: message };
53
+ }
54
+ export function missingPart(part, error) {
55
+ const failure = toFailure(error);
56
+ return { part, code: failure.code, error: failure.error };
57
+ }
58
+ /**
59
+ * Collects the parts of a composite answer that could not be read.
60
+ *
61
+ * <p>Mirrors `PartialData`: nothing is recorded while every part succeeded, and `applyTo` adds
62
+ * `partial: true` plus the entries only when at least one did not.
63
+ */
64
+ export class MissingParts {
65
+ parts = [];
66
+ add(part, error) {
67
+ this.parts.push(missingPart(part, error));
68
+ }
69
+ addAll(parts) {
70
+ this.parts.push(...parts);
71
+ }
72
+ get isEmpty() {
73
+ return this.parts.length === 0;
74
+ }
75
+ get entries() {
76
+ return this.parts;
77
+ }
78
+ applyTo(out) {
79
+ if (this.parts.length === 0) {
80
+ return out;
81
+ }
82
+ return { ...out, partial: true, missing: [...this.parts] };
83
+ }
84
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The wire shapes of the McInsight HTTP API.
3
+ *
4
+ * <p>These mirror the mod's own types: `Page` for pagination, `ViewerModel`/`ViewerJson` for recipe
5
+ * viewer data, `StatusHandler` for status, and the per-kind collector output for the data endpoints.
6
+ * They live in one place so a shape change is a compile error in the data layer rather than a
7
+ * silently ignored property, and so no tool re-declares a response inline.
8
+ */
9
+ export {};