1use rmcp::ErrorData as McpError;
39use rmcp::handler::server::{router::prompt::PromptRouter, tool::ToolRouter, wrapper::Parameters};
40use rmcp::model::{
41 Annotated, CallToolResult, CompletionInfo, CompleteRequestParams, CompleteResult,
42 Content, ErrorCode, GetPromptRequestParams, GetPromptResult,
43 ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult,
44 PaginatedRequestParams, PromptMessage, PromptMessageRole,
45 RawResource, ReadResourceRequestParams, ReadResourceResult,
46 ResourceContents, ServerCapabilities, ServerInfo, SetLevelRequestParams,
47};
48use rmcp::schemars::JsonSchema;
49use rmcp::service::RequestContext;
50use rmcp::{prompt, prompt_handler, prompt_router, tool, tool_handler, tool_router, RoleServer};
51use serde::{Deserialize, Serialize};
52
53use std::collections::{BTreeMap, HashMap, HashSet};
54use std::sync::Arc;
55use std::path::PathBuf;
56
57use rpfm_ipc::helpers::DataSource;
58use rpfm_ipc::messages::{Command, Response};
59use rpfm_lib::files::{ContainerPath, RFile, RFileDecoded};
60use rpfm_telemetry::sentry;
61
62use crate::session::{Session, recv_response};
63
64macro_rules! send_and_respond {
73 ($self:expr, $tool_name:expr, $cmd:expr) => {{
74 let tx_ctx = sentry::TransactionContext::new(
75 &format!("tools/call {}", $tool_name),
76 "mcp.server",
77 );
78 let tx = sentry::start_transaction(tx_ctx);
79 tx.set_data("mcp.method.name", sentry::protocol::Value::from("tools/call"));
80 tx.set_data("mcp.tool.name", sentry::protocol::Value::from($tool_name));
81 tx.set_data("mcp.transport", sentry::protocol::Value::from("streamable-http"));
82
83 sentry::configure_scope(|scope| scope.set_span(Some(tx.clone().into())));
84
85 let mut receiver = $self.session.send($cmd);
86 let response = recv_response(&mut receiver).await;
87
88 tx.finish();
89
90 let is_error = matches!(&response, Response::Error(_));
91
92 let json = serde_json::to_string(&response).map_err(|e| McpError {
93 code: ErrorCode::INTERNAL_ERROR,
94 message: format!("Failed to serialize response: {e}").into(),
95 data: None,
96 })?;
97
98 if is_error {
99 Ok(CallToolResult::error(vec![Content::text(json)]))
100 } else {
101 Ok(CallToolResult::success(vec![Content::text(json)]))
102 }
103 }};
104}
105
106fn resource(uri: &str, name: &str, description: &str, mime_type: &str) -> Annotated<RawResource> {
108 let mut raw = RawResource::new(uri, name);
109 raw.description = Some(description.into());
110 raw.mime_type = Some(mime_type.into());
111 Annotated { raw, annotations: None }
112}
113
114macro_rules! parse_json {
120 ($input:expr) => {
121 match serde_json::from_str($input) {
122 Ok(v) => v,
123 Err(e) => return Ok(CallToolResult::error(vec![Content::text(format!("Invalid JSON parameter: {e}"))])),
124 }
125 };
126}
127
128#[derive(Clone)]
142pub struct McpServer {
143 session: Arc<Session>,
145 tool_router: ToolRouter<Self>,
147 prompt_router: PromptRouter<Self>,
149}
150
151#[derive(Debug, Deserialize, JsonSchema, Serialize)]
154#[schemars(description = "Call any IPC command directly.")]
155pub struct CallCommandArgs {
156 pub command: String,
158}
159
160#[derive(Debug, Deserialize, JsonSchema, Serialize)]
161pub struct OpenPackfilesArgs {
162 pub paths: Vec<PathBuf>,
164}
165
166#[derive(Debug, Deserialize, JsonSchema, Serialize)]
167pub struct SetGameSelectedArgs {
168 pub game_name: String,
170 pub rebuild_dependencies: bool,
172}
173
174#[derive(Debug, Deserialize, JsonSchema, Serialize)]
175pub struct TsvExportArgs {
176 pub pack_key: String,
178 pub tsv_path: PathBuf,
180 pub table_path: String,
182}
183
184#[derive(Debug, Deserialize, JsonSchema, Serialize)]
185pub struct TsvImportArgs {
186 pub pack_key: String,
188 pub tsv_path: PathBuf,
190 pub table_path: String,
192}
193
194#[derive(Debug, Deserialize, JsonSchema, Serialize)]
195pub struct DecodePackedFileArgs {
196 pub pack_key: String,
198 pub path: String,
200 pub source: DataSource,
202}
203
204#[derive(Debug, Deserialize, JsonSchema, Serialize)]
207pub struct PathArg {
208 pub path: PathBuf,
210}
211
212#[derive(Debug, Deserialize, JsonSchema, Serialize)]
215pub struct PackKeyArg {
216 pub pack_key: String,
218}
219
220#[derive(Debug, Deserialize, JsonSchema, Serialize)]
221pub struct PackKeyBoolArg {
222 pub pack_key: String,
224 pub value: bool,
226}
227
228#[derive(Debug, Deserialize, JsonSchema, Serialize)]
229pub struct PackKeyStringArg {
230 pub pack_key: String,
232 pub value: String,
234}
235
236#[derive(Debug, Deserialize, JsonSchema, Serialize)]
237pub struct PackKeyStringsArg {
238 pub pack_key: String,
240 pub values: Vec<String>,
242}
243
244#[derive(Debug, Deserialize, JsonSchema, Serialize)]
245pub struct PackKeyPathArg {
246 pub pack_key: String,
248 pub path: PathBuf,
250}
251
252#[derive(Debug, Deserialize, JsonSchema, Serialize)]
255pub struct SetPackFileTypeArgs {
256 pub pack_key: String,
258 pub pack_file_type: String,
260}
261
262#[derive(Debug, Deserialize, JsonSchema, Serialize)]
263pub struct ChangeCompressionFormatArgs {
264 pub pack_key: String,
266 pub format: String,
268}
269
270#[derive(Debug, Deserialize, JsonSchema, Serialize)]
271pub struct BoolArg {
272 pub value: bool,
274}
275
276#[derive(Debug, Deserialize, JsonSchema, Serialize)]
277pub struct SetPackSettingsArgs {
278 pub pack_key: String,
280 pub settings: String,
282}
283
284#[derive(Debug, Deserialize, JsonSchema, Serialize)]
285pub struct SetDependencyPackFilesListArgs {
286 pub pack_key: String,
288 pub list: String,
290}
291
292#[derive(Debug, Deserialize, JsonSchema, Serialize)]
295pub struct NewPackedFileArgs {
296 pub pack_key: String,
298 pub path: String,
300 pub new_file: String,
302}
303
304#[derive(Debug, Deserialize, JsonSchema, Serialize)]
305pub struct AddPackedFilesArgs {
306 pub pack_key: String,
308 pub source_paths: Vec<PathBuf>,
310 pub destination_paths: String,
312 pub ignore_paths: Option<Vec<PathBuf>>,
314}
315
316#[derive(Debug, Deserialize, JsonSchema, Serialize)]
317pub struct AddPackedFilesFromPackFileArgs {
318 pub pack_key: String,
320 pub source_pack_path: String,
322 pub container_paths: String,
324}
325
326#[derive(Debug, Deserialize, JsonSchema, Serialize)]
327pub struct AddPackedFilesFromPackFileToAnimpackArgs {
328 pub source_pack_key: String,
330 pub pack_key: String,
332 pub animpack_path: String,
334 pub container_paths: String,
336}
337
338#[derive(Debug, Deserialize, JsonSchema, Serialize)]
339pub struct AddPackedFilesFromAnimpackArgs {
340 pub anim_pack_key: String,
342 pub pack_key: String,
344 pub source: DataSource,
346 pub animpack_path: String,
348 pub container_paths: String,
350}
351
352#[derive(Debug, Deserialize, JsonSchema, Serialize)]
353pub struct ContainerPathsArg {
354 pub pack_key: String,
356 pub paths: String,
358}
359
360#[derive(Debug, Deserialize, JsonSchema, Serialize)]
361pub struct DeleteFromAnimpackArgs {
362 pub pack_key: String,
364 pub animpack_path: String,
366 pub container_paths: String,
368}
369
370#[derive(Debug, Deserialize, JsonSchema, Serialize)]
371pub struct ExtractPackedFilesArgs {
372 pub pack_key: String,
374 pub source_paths: String,
376 pub destination_path: PathBuf,
378 pub export_as_tsv: bool,
380}
381
382#[derive(Debug, Deserialize, JsonSchema, Serialize)]
383pub struct RenamePackedFilesArgs {
384 pub pack_key: String,
386 pub renames: String,
388}
389
390#[derive(Debug, Deserialize, JsonSchema, Serialize)]
391pub struct CopyOrCutPackedFilesArgs {
392 pub paths_by_pack: String,
394}
395
396#[derive(Debug, Deserialize, JsonSchema, Serialize)]
397pub struct PastePackedFilesArgs {
398 pub pack_key: String,
400 pub destination_path: String,
402}
403
404#[derive(Debug, Deserialize, JsonSchema, Serialize)]
405pub struct DuplicatePackedFilesArgs {
406 pub pack_key: String,
408 pub paths: String,
410}
411
412#[derive(Debug, Deserialize, JsonSchema, Serialize)]
413pub struct SavePackedFileFromViewArgs {
414 pub pack_key: String,
416 pub path: String,
418 pub data: String,
420}
421
422#[derive(Debug, Deserialize, JsonSchema, Serialize)]
423pub struct SavePackedFileFromExternalViewArgs {
424 pub pack_key: String,
426 pub internal_path: String,
428 pub external_path: PathBuf,
430}
431
432#[derive(Debug, Deserialize, JsonSchema, Serialize)]
433pub struct SavePackedFilesToPackFileAndCleanArgs {
434 pub pack_key: String,
436 pub files: String,
438 pub optimize: bool,
440}
441
442#[derive(Debug, Deserialize, JsonSchema, Serialize)]
443pub struct StringArg {
444 pub value: String,
446}
447
448#[derive(Debug, Deserialize, JsonSchema, Serialize)]
449pub struct OpenPackedFileInExternalProgramArgs {
450 pub pack_key: String,
452 pub source: DataSource,
454 pub container_path: String,
456}
457
458#[derive(Debug, Deserialize, JsonSchema, Serialize)]
459pub struct StringsArg {
460 pub values: Vec<String>,
462}
463
464#[derive(Debug, Deserialize, JsonSchema, Serialize)]
467pub struct ImportDependenciesArgs {
468 pub pack_key: String,
470 pub paths: String,
472}
473
474#[derive(Debug, Deserialize, JsonSchema, Serialize)]
475pub struct GetRFilesFromAllSourcesArgs {
476 pub paths: String,
478 pub lowercase: bool,
480}
481
482#[derive(Debug, Deserialize, JsonSchema, Serialize)]
483pub struct ContainerPathArg {
484 pub path: String,
486}
487
488#[derive(Debug, Deserialize, JsonSchema, Serialize)]
491pub struct GlobalSearchArgs {
492 pub pack_key: String,
494 pub search: String,
496}
497
498#[derive(Debug, Deserialize, JsonSchema, Serialize)]
499pub struct GlobalSearchReplaceMatchesArgs {
500 pub pack_key: String,
502 pub search: String,
504 pub matches: String,
506}
507
508#[derive(Debug, Deserialize, JsonSchema, Serialize)]
509pub struct SearchReferencesArgs {
510 pub pack_key: String,
512 pub reference_map: String,
514 pub value: String,
516}
517
518#[derive(Debug, Deserialize, JsonSchema, Serialize)]
519pub struct GetReferenceDataFromDefinitionArgs {
520 pub pack_key: String,
522 pub table_name: String,
524 pub definition: String,
526 pub force: bool,
528}
529
530#[derive(Debug, Deserialize, JsonSchema, Serialize)]
531pub struct GoToDefinitionArgs {
532 pub pack_key: String,
534 pub table_name: String,
536 pub column_name: String,
538 pub values: Vec<String>,
540}
541
542#[derive(Debug, Deserialize, JsonSchema, Serialize)]
545pub struct SaveSchemaArgs {
546 pub schema: String,
548}
549
550#[derive(Debug, Deserialize, JsonSchema, Serialize)]
551pub struct StringI32Args {
552 pub name: String,
554 pub version: i32,
556}
557
558#[derive(Debug, Deserialize, JsonSchema, Serialize)]
559pub struct ReferencingColumnsForDefinitionArgs {
560 pub table_name: String,
562 pub definition: String,
564}
565
566#[derive(Debug, Deserialize, JsonSchema, Serialize)]
567pub struct DefinitionArg {
568 pub definition: String,
570}
571
572#[derive(Debug, Deserialize, JsonSchema, Serialize)]
573pub struct SchemaPatchArgs {
574 pub patches: String,
576}
577
578#[derive(Debug, Deserialize, JsonSchema, Serialize)]
581pub struct MergeFilesArgs {
582 pub pack_key: String,
584 pub paths: String,
586 pub merged_path: String,
588 pub delete_source: bool,
590}
591
592#[derive(Debug, Deserialize, JsonSchema, Serialize)]
593pub struct CascadeEditionArgs {
594 pub pack_key: String,
596 pub table_name: String,
598 pub definition: String,
600 pub changes: String,
602}
603
604#[derive(Debug, Deserialize, JsonSchema, Serialize)]
605pub struct AddKeysToKeyDeletesArgs {
606 pub pack_key: String,
608 pub table_file_name: String,
610 pub key_table_name: String,
612 pub keys: HashSet<String>,
614}
615
616#[derive(Debug, Deserialize, JsonSchema, Serialize)]
619pub struct DiagnosticsCheckArgs {
620 pub ignored: Vec<String>,
622 pub check_ak_only_refs: bool,
624}
625
626#[derive(Debug, Deserialize, JsonSchema, Serialize)]
627pub struct DiagnosticsUpdateArgs {
628 pub diagnostics: String,
630 pub paths: String,
632 pub check_ak_only_refs: bool,
634}
635
636#[derive(Debug, Deserialize, JsonSchema, Serialize)]
639pub struct AddNoteArgs {
640 pub pack_key: String,
642 pub note: String,
644}
645
646#[derive(Debug, Deserialize, JsonSchema, Serialize)]
647pub struct DeleteNoteArgs {
648 pub pack_key: String,
650 pub path: String,
652 pub id: u64,
654}
655
656#[derive(Debug, Deserialize, JsonSchema, Serialize)]
659pub struct OptimizePackFileArgs {
660 pub pack_key: String,
662 pub options: String,
664}
665
666#[derive(Debug, Deserialize, JsonSchema, Serialize)]
669pub struct SettingsSetBoolArgs {
670 pub key: String,
672 pub value: bool,
674}
675
676#[derive(Debug, Deserialize, JsonSchema, Serialize)]
677pub struct SettingsSetI32Args {
678 pub key: String,
680 pub value: i32,
682}
683
684#[derive(Debug, Deserialize, JsonSchema, Serialize)]
685pub struct SettingsSetF32Args {
686 pub key: String,
688 pub value: f32,
690}
691
692#[derive(Debug, Deserialize, JsonSchema, Serialize)]
693pub struct SettingsSetStringArgs {
694 pub key: String,
696 pub value: String,
698}
699
700#[derive(Debug, Deserialize, JsonSchema, Serialize)]
701pub struct SettingsSetPathBufArgs {
702 pub key: String,
704 pub value: PathBuf,
706}
707
708#[derive(Debug, Deserialize, JsonSchema, Serialize)]
709pub struct SettingsSetVecStringArgs {
710 pub key: String,
712 pub value: Vec<String>,
714}
715
716#[derive(Debug, Deserialize, JsonSchema, Serialize)]
717pub struct SettingsSetVecRawArgs {
718 pub key: String,
720 pub value: Vec<u8>,
722}
723
724#[derive(Debug, Deserialize, JsonSchema, Serialize)]
727pub struct InitializeMyModFolderArgs {
728 pub name: String,
730 pub game: String,
732 pub sublime: bool,
734 pub vscode: bool,
736 pub gitignore: Option<String>,
738}
739
740#[derive(Debug, Deserialize, JsonSchema, Serialize)]
741pub struct PackMapArgs {
742 pub pack_key: String,
744 pub tile_maps: Vec<PathBuf>,
746 pub tiles: String,
748}
749
750#[derive(Debug, Deserialize, JsonSchema, Serialize)]
751pub struct BuildStarposArgs {
752 pub pack_key: String,
754 pub campaign_id: String,
756 pub process_hlp_spd: bool,
758}
759
760#[derive(Debug, Deserialize, JsonSchema, Serialize)]
761pub struct UpdateAnimIdsArgs {
762 pub pack_key: String,
764 pub starting_id: i32,
766 pub offset: i32,
768}
769
770#[derive(Debug, Deserialize, JsonSchema, Serialize)]
771pub struct ExportRigidToGltfArgs {
772 pub rigid_model: String,
774 pub output_path: String,
776}
777
778#[derive(Debug, Deserialize, JsonSchema, Serialize)]
779pub struct SetVideoFormatArgs {
780 pub pack_key: String,
782 pub path: String,
784 pub format: String,
786}
787
788#[derive(Debug, Deserialize, JsonSchema, Serialize)]
789pub struct GetPackTranslationArgs {
790 pub pack_key: String,
792 pub language: String,
794}
795
796#[tool_handler(router = self.tool_router)]
801#[prompt_handler(router = self.prompt_router)]
802impl rmcp::ServerHandler for McpServer {
803 fn get_info(&self) -> ServerInfo {
804 let capabilities = ServerCapabilities::builder()
805 .enable_tools()
806 .enable_prompts()
807 .enable_resources()
808 .enable_completions()
809 .enable_logging()
810 .build();
811
812 ServerInfo::new(capabilities).with_instructions("\
814This is the MCP server for RPFM (Rusted PackFile Manager), a tool for modding Total War games by \
815Creative Assembly. It lets you read, edit, create, and manage PackFiles (.pack) — the archive \
816format used by all modern Total War titles.
817
818## Key Concepts
819
820- **PackFile**: An archive containing game data files (DB tables, localisation, textures, models, etc.). \
821 Mods are distributed as PackFiles.
822- **pack_key**: When you open one or more PackFiles, each gets a unique key string. Use `list_open_packs` \
823 to discover available keys. Most tools require a `pack_key` parameter.
824- **DataSource**: Where data lives — `\"PackFile\"` (the user's mod), `\"GameFiles\"` (vanilla game data), \
825 `\"ParentFiles\"` (dependency mods), `\"AssKitFiles\"` (Assembly Kit data), `\"ExternalFile\"` (disk file).
826- **ContainerPath**: A path inside a pack — either `{\"File\": \"db/land_units_tables/my_table\"}` or \
827 `{\"Folder\": \"db/land_units_tables\"}`. Use an empty string for root folder.
828
829## Required Initialization Sequence
830
8311. **Set the game** — Call `set_game_selected` with the game key (e.g. `\"warhammer_3\"`) and \
832 `rebuild_dependencies: true`. This loads schemas and vanilla data.
8332. **Open a pack** — Call `open_packfiles` with filesystem path(s). Note the returned pack key(s).
8343. **Verify schema** — Call `is_schema_loaded`; if false, call `update_schemas` first.
835
836## Supported Games
837
838Valid game keys: `pharaoh_dynasties`, `pharaoh`, `warhammer_3`, `troy`, `three_kingdoms`, \
839`warhammer_2`, `warhammer`, `thrones_of_britannia`, `attila`, `rome_2`, `shogun_2`, `napoleon`, \
840`empire`, `arena`.
841
842## Common File Path Conventions
843
844- DB tables: `db/<table_name>/<file_name>` (e.g. `db/land_units_tables/my_mod`)
845- Localisation: `text/db/<file_name>.loc`
846- Scripts: `script/<path>.lua`
847- Images: `ui/<path>.png`
848
849## Pack File Types (PFHFileType)
850
851`\"Boot\"`, `\"Release\"`, `\"Patch\"`, `\"Mod\"` (default for mods), `\"Movie\"`.
852
853## Compression Formats
854
855`\"None\"` (default), `\"Lzma1\"` (legacy), `\"Lz4\"` (WH3 6.2+), `\"Zstd\"` (WH3 6.2+).
856
857## Creating New Files (NewFile)
858
859- DB table: `{\"DB\": [\"file_name\", \"table_name\", version]}` — e.g. `{\"DB\": [\"my_mod\", \"land_units_tables\", 0]}`
860- Loc file: `{\"Loc\": \"file_name\"}`
861- Text file: `{\"Text\": [\"file_name\", \"Plain\"]}` — formats: `\"Plain\"`, `\"Html\"`, `\"Xml\"`, `\"Lua\"`, `\"Cpp\"`, `\"Json\"`, `\"Markdown\"`, `\"Smithy\"`
862- AnimPack: `{\"AnimPack\": \"file_name\"}`
863- PortraitSettings: `{\"PortraitSettings\": [\"file_name\", version, [[\"entry_key\", \"entry_value\"]]]}`
864- VMD: `{\"VMD\": \"file_name\"}`
865- WSModel: `{\"WSModel\": \"file_name\"}`
866
867## Resources
868
869Use `resources/list` and `resources/read` to browse reference data: valid enum values, game lists, \
870and example JSON payloads without needing tool calls.
871
872## Responses
873
874All tool responses are JSON-serialized. On failure, an error message is returned instead of the expected data.
875")
876 }
877
878 async fn list_resources(
883 &self,
884 _request: Option<PaginatedRequestParams>,
885 _context: RequestContext<RoleServer>,
886 ) -> Result<ListResourcesResult, McpError> {
887 let resources = vec![
888 resource("rpfm://games", "games", "List of all supported Total War game keys.", "application/json"),
889 resource("rpfm://enums/PFHFileType", "PFHFileType", "Valid PackFile type values (Boot, Release, Patch, Mod, Movie).", "application/json"),
890 resource("rpfm://enums/CompressionFormat", "CompressionFormat", "Valid compression format values (None, Lzma1, Lz4, Zstd).", "application/json"),
891 resource("rpfm://enums/DataSource", "DataSource", "Valid data source values indicating where data comes from.", "application/json"),
892 resource("rpfm://enums/ContainerPath", "ContainerPath", "ContainerPath enum variants with JSON examples.", "application/json"),
893 resource("rpfm://enums/NewFile", "NewFile", "NewFile enum variants for creating files inside packs, with JSON examples.", "application/json"),
894 resource("rpfm://enums/SupportedFormats", "SupportedFormats", "Valid video format values (CaVp8, Ivf).", "application/json"),
895 resource("rpfm://examples/global_search", "GlobalSearch example", "Example JSON for the GlobalSearch struct used by search tools.", "application/json"),
896 resource("rpfm://examples/optimizer_options", "OptimizerOptions example", "Example JSON for OptimizerOptions with all boolean fields.", "application/json"),
897 resource("rpfm://reference/initialization", "Initialization guide", "Step-by-step guide for initializing the RPFM MCP server session.", "text/plain"),
898 resource("rpfm://reference/path_conventions", "Path conventions", "Common file path conventions inside Total War PackFiles.", "text/plain"),
899 ];
900 Ok(ListResourcesResult {
901 resources,
902 ..Default::default()
903 })
904 }
905
906 async fn list_resource_templates(
907 &self,
908 _request: Option<PaginatedRequestParams>,
909 _context: RequestContext<RoleServer>,
910 ) -> Result<ListResourceTemplatesResult, McpError> {
911 Ok(ListResourceTemplatesResult {
912 resource_templates: vec![],
913 ..Default::default()
914 })
915 }
916
917 async fn read_resource(
918 &self,
919 request: ReadResourceRequestParams,
920 _context: RequestContext<RoleServer>,
921 ) -> Result<ReadResourceResult, McpError> {
922 let uri = &request.uri;
923 let content = match uri.as_str() {
924 "rpfm://games" => serde_json::json!({
925 "supported_games": [
926 {"key": "pharaoh_dynasties", "display_name": "Total War: Pharaoh Dynasties"},
927 {"key": "pharaoh", "display_name": "Total War: Pharaoh"},
928 {"key": "warhammer_3", "display_name": "Total War: Warhammer III"},
929 {"key": "troy", "display_name": "A Total War Saga: Troy"},
930 {"key": "three_kingdoms", "display_name": "Total War: Three Kingdoms"},
931 {"key": "warhammer_2", "display_name": "Total War: Warhammer II"},
932 {"key": "warhammer", "display_name": "Total War: Warhammer"},
933 {"key": "thrones_of_britannia", "display_name": "A Total War Saga: Thrones of Britannia"},
934 {"key": "attila", "display_name": "Total War: Attila"},
935 {"key": "rome_2", "display_name": "Total War: Rome II"},
936 {"key": "shogun_2", "display_name": "Total War: Shogun 2"},
937 {"key": "napoleon", "display_name": "Total War: Napoleon"},
938 {"key": "empire", "display_name": "Total War: Empire"},
939 {"key": "arena", "display_name": "Total War: Arena"}
940 ]
941 }).to_string(),
942
943 "rpfm://enums/PFHFileType" => serde_json::json!({
944 "enum": "PFHFileType",
945 "description": "The type/priority of a PackFile. Games load packs in type order (Boot first, Movie last).",
946 "variants": [
947 {"name": "Boot", "value": 0, "description": "Core game boot files, loaded first."},
948 {"name": "Release", "value": 1, "description": "Main game data files."},
949 {"name": "Patch", "value": 2, "description": "Official patch and update files."},
950 {"name": "Mod", "value": 3, "description": "User mod files. This is the default for mods."},
951 {"name": "Movie", "value": 4, "description": "Cinematic and always-loaded files, loaded last."}
952 ],
953 "json_example": "\"Mod\""
954 }).to_string(),
955
956 "rpfm://enums/CompressionFormat" => serde_json::json!({
957 "enum": "CompressionFormat",
958 "description": "Compression algorithm for pack file data.",
959 "variants": [
960 {"name": "None", "description": "No compression (default)."},
961 {"name": "Lzma1", "description": "Legacy LZMA compression (all PFH5 games)."},
962 {"name": "Lz4", "description": "LZ4 compression (Warhammer 3 v6.2+)."},
963 {"name": "Zstd", "description": "Zstandard compression (Warhammer 3 v6.2+)."}
964 ],
965 "json_example": "\"None\""
966 }).to_string(),
967
968 "rpfm://enums/DataSource" => serde_json::json!({
969 "enum": "DataSource",
970 "description": "Identifies where data comes from when working with files.",
971 "variants": [
972 {"name": "PackFile", "description": "Data from the user's currently open pack (mod files)."},
973 {"name": "GameFiles", "description": "Data from vanilla game files."},
974 {"name": "ParentFiles", "description": "Data from parent/dependency pack files."},
975 {"name": "AssKitFiles", "description": "Data from the Assembly Kit (modding tools)."},
976 {"name": "ExternalFile", "description": "Data from an external file on disk."}
977 ],
978 "json_example": "\"PackFile\""
979 }).to_string(),
980
981 "rpfm://enums/ContainerPath" => serde_json::json!({
982 "enum": "ContainerPath",
983 "description": "A path reference inside a PackFile, pointing to either a file or a folder.",
984 "variants": [
985 {
986 "name": "File",
987 "description": "Path to a single file inside the pack.",
988 "json_example": {"File": "db/land_units_tables/my_table"}
989 },
990 {
991 "name": "Folder",
992 "description": "Path to a folder inside the pack. Use empty string for root.",
993 "json_example": {"Folder": "db/land_units_tables"}
994 }
995 ],
996 "usage_notes": "Most tools accept a JSON array of ContainerPath objects, e.g. [{\"File\": \"path1\"}, {\"Folder\": \"path2\"}]"
997 }).to_string(),
998
999 "rpfm://enums/NewFile" => serde_json::json!({
1000 "enum": "NewFile",
1001 "description": "Specifies what type of file to create inside a pack.",
1002 "variants": [
1003 {
1004 "name": "DB",
1005 "description": "Create a new DB table. Args: [file_name, table_name, version].",
1006 "json_example": {"DB": ["my_mod", "land_units_tables", 0]}
1007 },
1008 {
1009 "name": "Loc",
1010 "description": "Create a new localisation file. Arg: file_name.",
1011 "json_example": {"Loc": "my_mod"}
1012 },
1013 {
1014 "name": "Text",
1015 "description": "Create a new text file. Args: [file_name, format]. Formats: Bat, Cpp, Html, Hlsl, Json, Js, Css, Lua, Markdown, Plain, Python, Sql, Xml, Yaml.",
1016 "json_example": {"Text": ["my_script", "Lua"]}
1017 },
1018 {
1019 "name": "AnimPack",
1020 "description": "Create a new AnimPack file. Arg: file_name.",
1021 "json_example": {"AnimPack": "my_anim"}
1022 },
1023 {
1024 "name": "PortraitSettings",
1025 "description": "Create a new portrait settings file. Args: [file_name, version, entries].",
1026 "json_example": {"PortraitSettings": ["my_portraits", 3, []]}
1027 },
1028 {
1029 "name": "VMD",
1030 "description": "Create a new VMD file. Arg: file_name.",
1031 "json_example": {"VMD": "my_vmd"}
1032 },
1033 {
1034 "name": "WSModel",
1035 "description": "Create a new WSModel file. Arg: file_name.",
1036 "json_example": {"WSModel": "my_model"}
1037 }
1038 ]
1039 }).to_string(),
1040
1041 "rpfm://enums/SupportedFormats" => serde_json::json!({
1042 "enum": "SupportedFormats",
1043 "description": "Video format options for CA VP8 video files.",
1044 "variants": [
1045 {"name": "CaVp8", "description": "CA's custom VP8 format (default)."},
1046 {"name": "Ivf", "description": "Standard VP8 IVF format."}
1047 ],
1048 "json_example": "\"CaVp8\""
1049 }).to_string(),
1050
1051 "rpfm://examples/global_search" => serde_json::json!({
1052 "description": "Example GlobalSearch JSON for use with global_search, global_search_replace_all, etc.",
1053 "example": {
1054 "pattern": "old_unit_name",
1055 "replace_text": "new_unit_name",
1056 "case_sensitive": false,
1057 "use_regex": false,
1058 "sources": [{"Pack": "my_mod.pack"}],
1059 "search_on": {
1060 "anim": false, "anim_fragment_battle": false, "anim_pack": false,
1061 "anims_table": false, "atlas": false, "audio": false, "bmd": false,
1062 "db": true, "esf": false, "group_formations": false, "image": false,
1063 "loc": true, "matched_combat": false, "pack": false,
1064 "portrait_settings": false, "rigid_model": false, "sound_bank": false,
1065 "text": true, "uic": false, "unit_variant": false, "unknown": false,
1066 "video": false, "schema": false
1067 },
1068 "matches": {
1069 "anim": [], "anim_fragment_battle": [], "anim_pack": [],
1070 "anims_table": [], "atlas": [], "audio": [], "bmd": [],
1071 "db": [], "esf": [], "group_formations": [], "image": [],
1072 "loc": [], "matched_combat": [], "pack": [],
1073 "portrait_settings": [], "rigid_model": [], "sound_bank": [],
1074 "text": [], "uic": [], "unit_variant": [], "unknown": [],
1075 "video": [], "schema": {"matches": []}
1076 },
1077 "game_key": "warhammer_3"
1078 },
1079 "notes": "The `matches` field is populated by the search results. When calling `global_search`, pass it empty. The `sources` field uses SearchSource: {\"Pack\": \"key\"}, \"ParentFiles\", \"GameFiles\", \"AssKitFiles\"."
1080 }).to_string(),
1081
1082 "rpfm://examples/optimizer_options" => serde_json::json!({
1083 "description": "OptimizerOptions struct with all boolean fields for pack optimization.",
1084 "example": {
1085 "pack_remove_itm_files": true,
1086 "pack_apply_compression": true,
1087 "pack_remove_duplicated_files": false,
1088 "db_import_datacores_into_twad_key_deletes": false,
1089 "db_optimize_datacored_tables": false,
1090 "table_remove_duplicated_entries": true,
1091 "table_remove_itm_entries": true,
1092 "table_remove_itnr_entries": true,
1093 "table_remove_empty_file": true,
1094 "text_remove_unused_xml_map_folders": false,
1095 "text_remove_unused_xml_prefab_folder": false,
1096 "text_remove_agf_files": false,
1097 "text_remove_model_statistics_files": false,
1098 "pts_remove_unused_art_sets": false,
1099 "pts_remove_unused_variants": false,
1100 "pts_remove_empty_masks": false,
1101 "pts_remove_empty_file": false
1102 },
1103 "field_descriptions": {
1104 "pack_remove_itm_files": "Remove files identical to vanilla (Identical To Master).",
1105 "pack_apply_compression": "Apply the most modern compression format the active game supports (overriding the pack's configured one), so the next save compresses the files.",
1106 "pack_remove_duplicated_files": "Remove case-insensitively duplicated files (same name ignoring casing) when their contents are identical, keeping the all-lowercase one or, failing that, the last one.",
1107 "db_import_datacores_into_twad_key_deletes": "Import datacored tables into TWAD key deletes.",
1108 "db_optimize_datacored_tables": "Optimize datacored tables.",
1109 "table_remove_duplicated_entries": "Remove duplicate rows in tables.",
1110 "table_remove_itm_entries": "Remove rows identical to vanilla.",
1111 "table_remove_itnr_entries": "Remove rows identical to vanilla that are not referenced.",
1112 "table_remove_empty_file": "Remove tables with no rows.",
1113 "text_remove_unused_xml_map_folders": "Remove unused XML files in map folders.",
1114 "text_remove_unused_xml_prefab_folder": "Remove unused XML files in prefab folders.",
1115 "text_remove_agf_files": "Remove AGF files.",
1116 "text_remove_model_statistics_files": "Remove model statistics files.",
1117 "pts_remove_unused_art_sets": "Remove unused art sets in portrait settings.",
1118 "pts_remove_unused_variants": "Remove unused variants in portrait settings.",
1119 "pts_remove_empty_masks": "Remove empty masks in portrait settings.",
1120 "pts_remove_empty_file": "Remove empty portrait settings files."
1121 }
1122 }).to_string(),
1123
1124 "rpfm://reference/initialization" => "\
1125RPFM MCP Server Initialization Guide
1126=====================================
1127
1128Before you can work with PackFiles, you must initialize the server session:
1129
1130Step 1: Set the game
1131 Call: set_game_selected(game_name: \"warhammer_3\", rebuild_dependencies: true)
1132 This loads the correct schemas and vanilla game data for the selected title.
1133 Valid game keys: pharaoh_dynasties, pharaoh, warhammer_3, troy, three_kingdoms,
1134 warhammer_2, warhammer, thrones_of_britannia, attila, rome_2, shogun_2,
1135 napoleon, empire, arena.
1136
1137Step 2: Verify schema is loaded
1138 Call: is_schema_loaded()
1139 If it returns false, call update_schemas() to download the latest schemas.
1140
1141Step 3: Open a PackFile
1142 Call: open_packfiles(paths: [\"/path/to/my_mod.pack\"])
1143 The response returns pack info including the pack_key you'll use for all
1144 subsequent operations.
1145
1146Step 4: Verify dependencies (optional but recommended)
1147 Call: is_there_a_dependency_database(value: true)
1148 If false, call generate_dependencies_cache() to build the dependency database.
1149
1150After initialization, use list_open_packs() to see all open pack keys at any time.
1151".to_string(),
1152
1153 "rpfm://reference/path_conventions" => "\
1154Total War PackFile Path Conventions
1155====================================
1156
1157Files inside PackFiles follow specific path conventions:
1158
1159DB Tables:
1160 db/<table_name>/<file_name>
1161 Example: db/land_units_tables/my_mod
1162 Example: db/unit_stats_land_tables/custom_units
1163
1164Localisation (Loc) files:
1165 text/db/<file_name>.loc
1166 text/<file_name>.loc
1167 Example: text/db/my_mod.loc
1168
1169Scripts:
1170 script/<path>.lua
1171 script/campaign/mod/<script_name>.lua
1172 Example: script/campaign/mod/my_mod_script.lua
1173
1174UI Images:
1175 ui/<path>.png
1176 Path may vary depending on the purpose of the image.
1177
1178Models and Animations:
1179 variantmeshes/<path>
1180 animations/<path>
1181 Example: variantmeshes/wh_variantmodels/hu1/my_unit/my_unit.wsmodel
1182
1183Audio:
1184 audio/<path>.bnk
1185
1186Maps:
1187 terrain/tiles/battle/<map_name>/
1188".to_string(),
1189
1190 _ => {
1191 return Err(McpError {
1192 code: ErrorCode::INVALID_PARAMS,
1193 message: format!("Unknown resource URI: {uri}").into(),
1194 data: None,
1195 });
1196 }
1197 };
1198
1199 Ok(ReadResourceResult::new(vec![ResourceContents::text(content, uri.clone())]))
1200 }
1201
1202 async fn complete(
1207 &self,
1208 request: CompleteRequestParams,
1209 _context: RequestContext<RoleServer>,
1210 ) -> Result<CompleteResult, McpError> {
1211 let argument_name = &request.argument.name;
1212 let partial = &request.argument.value;
1213
1214 let candidates: Vec<String> = match argument_name.as_str() {
1215 "game_name" | "game_key" | "game" => {
1216 let games = vec![
1217 "pharaoh_dynasties", "pharaoh", "warhammer_3", "troy",
1218 "three_kingdoms", "warhammer_2", "warhammer",
1219 "thrones_of_britannia", "attila", "rome_2", "shogun_2",
1220 "napoleon", "empire", "arena",
1221 ];
1222 games.into_iter()
1223 .filter(|g| g.starts_with(partial))
1224 .map(String::from)
1225 .collect()
1226 },
1227 "pack_file_type" => {
1228 let types = vec!["\"Boot\"", "\"Release\"", "\"Patch\"", "\"Mod\"", "\"Movie\""];
1229 types.into_iter()
1230 .filter(|t| t.starts_with(partial))
1231 .map(String::from)
1232 .collect()
1233 },
1234 "format" => {
1235 let formats = vec![
1237 "\"None\"", "\"Lzma1\"", "\"Lz4\"", "\"Zstd\"",
1238 "\"CaVp8\"", "\"Ivf\"",
1239 ];
1240 formats.into_iter()
1241 .filter(|f| f.starts_with(partial))
1242 .map(String::from)
1243 .collect()
1244 },
1245 "source" => {
1246 let sources = vec![
1247 "\"PackFile\"", "\"GameFiles\"", "\"ParentFiles\"",
1248 "\"AssKitFiles\"", "\"ExternalFile\"",
1249 ];
1250 sources.into_iter()
1251 .filter(|s| s.starts_with(partial))
1252 .map(String::from)
1253 .collect()
1254 },
1255 _ => vec![],
1256 };
1257
1258 let total = candidates.len() as u32;
1259 let values: Vec<String> = candidates.into_iter().take(100).collect();
1260 let has_more = total > 100;
1261
1262 Ok(CompleteResult::new(CompletionInfo {
1263 values,
1264 total: Some(total),
1265 has_more: Some(has_more),
1266 }))
1267 }
1268
1269 async fn set_level(
1274 &self,
1275 _request: SetLevelRequestParams,
1276 _context: RequestContext<RoleServer>,
1277 ) -> Result<(), McpError> {
1278 Ok(())
1282 }
1283}
1284
1285#[tool_router]
1286impl McpServer {
1287
1288 pub fn new(session: Arc<Session>) -> Self {
1289 Self {
1290 session,
1291 tool_router: McpServer::tool_router(),
1292 prompt_router: McpServer::prompt_router(),
1293 }
1294 }
1295
1296 #[tool(name = "call_command", description = "Call any IPC command directly. Use this for commands not yet wrapped as named tools.")]
1301 pub async fn call_command(&self, params: Parameters<CallCommandArgs>) -> Result<CallToolResult, McpError> {
1302 let command: Command = parse_json!(¶ms.0.command);
1303 send_and_respond!(self, "call_command", command)
1304 }
1305
1306 #[tool(description = "Create a new empty PackFile.")]
1311 pub async fn new_pack(&self) -> Result<CallToolResult, McpError> {
1312 send_and_respond!(self, "new_pack", Command::NewPack)
1313 }
1314
1315 #[tool(description = "Open one or more PackFiles. Returns the info about the open pack.")]
1316 pub async fn open_packfiles(&self, params: Parameters<OpenPackfilesArgs>) -> Result<CallToolResult, McpError> {
1317 send_and_respond!(self, "open_packfiles", Command::OpenPackFiles(params.0.paths))
1318 }
1319
1320 #[tool(description = "Save the pack identified by `pack_key`.")]
1321 pub async fn save_packfile(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1322 send_and_respond!(self, "save_packfile", Command::SavePack(params.0.pack_key))
1323 }
1324
1325 #[tool(description = "Close the pack identified by `pack_key` without saving. Any unsaved changes will be lost.")]
1326 pub async fn close_pack(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1327 send_and_respond!(self, "close_pack", Command::ClosePack(params.0.pack_key))
1328 }
1329
1330 #[tool(description = "Save the pack identified by `pack_key` to a new path.")]
1331 pub async fn save_pack_as(&self, params: Parameters<PackKeyPathArg>) -> Result<CallToolResult, McpError> {
1332 send_and_respond!(self, "save_pack_as", Command::SavePackAs(params.0.pack_key, params.0.path))
1333 }
1334
1335 #[tool(description = "Clean the pack identified by `pack_key` from corrupted files and save to a path. Use if normal save fails.")]
1336 pub async fn clean_and_save_pack_as(&self, params: Parameters<PackKeyPathArg>) -> Result<CallToolResult, McpError> {
1337 send_and_respond!(self, "clean_and_save_pack_as", Command::CleanAndSavePackAs(params.0.pack_key, params.0.path))
1338 }
1339
1340 #[tool(description = "Trigger a backup autosave for the pack identified by `pack_key`.")]
1341 pub async fn trigger_backup_autosave(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1342 send_and_respond!(self, "trigger_backup_autosave", Command::TriggerBackupAutosave(params.0.pack_key))
1343 }
1344
1345 #[tool(description = "Open all CA (vanilla) PackFiles for the selected game as one merged PackFile.")]
1346 pub async fn load_all_ca_pack_files(&self) -> Result<CallToolResult, McpError> {
1347 send_and_respond!(self, "load_all_ca_pack_files", Command::LoadAllCAPackFiles)
1348 }
1349
1350 #[tool(description = "Set the type of the pack identified by `pack_key`. Valid PFHFileType values: \"Boot\", \"Release\", \"Patch\", \"Mod\", \"Movie\". Example: pack_file_type = \"\\\"Mod\\\"\"")]
1355 pub async fn set_pack_file_type(&self, params: Parameters<SetPackFileTypeArgs>) -> Result<CallToolResult, McpError> {
1356 let pfh_type = parse_json!(¶ms.0.pack_file_type);
1357 send_and_respond!(self, "set_pack_file_type", Command::SetPackFileType(params.0.pack_key, pfh_type))
1358 }
1359
1360 #[tool(description = "Change the compression format of the pack identified by `pack_key`. Valid formats: \"None\", \"Lzma1\" (legacy), \"Lz4\" (WH3 6.2+), \"Zstd\" (WH3 6.2+). Example: format = \"\\\"None\\\"\"")]
1361 pub async fn change_compression_format(&self, params: Parameters<ChangeCompressionFormatArgs>) -> Result<CallToolResult, McpError> {
1362 let format = parse_json!(¶ms.0.format);
1363 send_and_respond!(self, "change_compression_format", Command::ChangeCompressionFormat(params.0.pack_key, format))
1364 }
1365
1366 #[tool(description = "Change whether the pack index includes timestamps for the pack identified by `pack_key`.")]
1367 pub async fn change_index_includes_timestamp(&self, params: Parameters<PackKeyBoolArg>) -> Result<CallToolResult, McpError> {
1368 send_and_respond!(self, "change_index_includes_timestamp", Command::ChangeIndexIncludesTimestamp(params.0.pack_key, params.0.value))
1369 }
1370
1371 #[tool(description = "Get the file path of the pack identified by `pack_key`.")]
1372 pub async fn get_pack_file_path(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1373 send_and_respond!(self, "get_pack_file_path", Command::GetPackFilePath(params.0.pack_key))
1374 }
1375
1376 #[tool(description = "Get the file name of the pack identified by `pack_key`.")]
1377 pub async fn get_pack_file_name(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1378 send_and_respond!(self, "get_pack_file_name", Command::GetPackFileName(params.0.pack_key))
1379 }
1380
1381 #[tool(description = "Get the settings of the pack identified by `pack_key`.")]
1382 pub async fn get_pack_settings(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1383 send_and_respond!(self, "get_pack_settings", Command::GetPackSettings(params.0.pack_key))
1384 }
1385
1386 #[tool(description = "Set the settings of the pack identified by `pack_key`. The `settings` is a PackSettings JSON object containing pack-level configuration.")]
1387 pub async fn set_pack_settings(&self, params: Parameters<SetPackSettingsArgs>) -> Result<CallToolResult, McpError> {
1388 let settings = parse_json!(¶ms.0.settings);
1389 send_and_respond!(self, "set_pack_settings", Command::SetPackSettings(params.0.pack_key, settings))
1390 }
1391
1392 #[tool(description = "Get the list of PackFiles marked as dependencies of the pack identified by `pack_key`.")]
1393 pub async fn get_dependency_pack_files_list(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1394 send_and_respond!(self, "get_dependency_pack_files_list", Command::GetDependencyPackFilesList(params.0.pack_key))
1395 }
1396
1397 #[tool(description = "Set the list of PackFiles marked as dependencies for the pack identified by `pack_key`. The `list` is a JSON array of [enabled, pack_name] pairs, e.g. [[true, \"other_mod.pack\"], [false, \"disabled_mod.pack\"]].")]
1398 pub async fn set_dependency_pack_files_list(&self, params: Parameters<SetDependencyPackFilesListArgs>) -> Result<CallToolResult, McpError> {
1399 let list = parse_json!(¶ms.0.list);
1400 send_and_respond!(self, "set_dependency_pack_files_list", Command::SetDependencyPackFilesList(params.0.pack_key, list))
1401 }
1402
1403 #[tool(description = "Decode a file from the pack identified by `pack_key`. The `path` is the internal file path (e.g. \"db/land_units_tables/my_mod\"). The `source` is the data source: \"PackFile\" (user mod), \"GameFiles\" (vanilla), \"ParentFiles\" (dependency mods), \"AssKitFiles\", or \"ExternalFile\". Returns the decoded file content as JSON (RFileDecoded).")]
1408 pub async fn decode_packed_file(&self, params: Parameters<DecodePackedFileArgs>) -> Result<CallToolResult, McpError> {
1409 send_and_respond!(self, "decode_packed_file", Command::DecodePackedFile(params.0.pack_key, params.0.path, params.0.source))
1410 }
1411
1412 #[tool(description = "Create a new file inside the pack identified by `pack_key`. The `path` is the destination path (e.g. \"db/land_units_tables/my_mod\"). NewFile types: {\"DB\": [\"file_name\", \"table_name\", version]}, {\"Loc\": \"name\"}, {\"Text\": [\"name\", \"Plain\"]}, {\"AnimPack\": \"name\"}, {\"VMD\": \"name\"}, {\"WSModel\": \"name\"}, {\"PortraitSettings\": [\"name\", version, []]}.")]
1413 pub async fn new_packed_file(&self, params: Parameters<NewPackedFileArgs>) -> Result<CallToolResult, McpError> {
1414 let new_file = parse_json!(¶ms.0.new_file);
1415 send_and_respond!(self, "new_packed_file", Command::NewPackedFile(params.0.pack_key, params.0.path, new_file))
1416 }
1417
1418 #[tool(description = "Add files from disk to the pack identified by `pack_key`. The `source_paths` are filesystem paths. The `destination_paths` is a JSON array of ContainerPath: [{\"File\": \"db/table/file\"}, {\"Folder\": \"ui/images\"}]. Optionally set `ignore_paths` to skip certain files.")]
1419 pub async fn add_packed_files(&self, params: Parameters<AddPackedFilesArgs>) -> Result<CallToolResult, McpError> {
1420 let dest: Vec<ContainerPath> = parse_json!(¶ms.0.destination_paths);
1421 send_and_respond!(self, "add_packed_files", Command::AddPackedFiles(params.0.pack_key, params.0.source_paths, dest, params.0.ignore_paths))
1422 }
1423
1424 #[tool(description = "Add files from another PackFile to the pack identified by `pack_key`. The `source_pack_path` is the pack path. The `container_paths` is a JSON array of ContainerPath: [{\"File\": \"path\"}].")]
1425 pub async fn add_packed_files_from_pack_file(&self, params: Parameters<AddPackedFilesFromPackFileArgs>) -> Result<CallToolResult, McpError> {
1426 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.container_paths);
1427 send_and_respond!(self, "add_packed_files_from_pack_file", Command::AddPackedFilesFromPackFile(params.0.pack_key, params.0.source_pack_path, paths))
1428 }
1429
1430 #[tool(description = "Copy files from the pack identified by `source_pack_key` into an AnimPack owned by `pack_key` (the two may differ). The `container_paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"animations/anim.anim\"}]. The `animpack_path` is the AnimPack's internal path.")]
1431 pub async fn add_packed_files_from_pack_file_to_animpack(&self, params: Parameters<AddPackedFilesFromPackFileToAnimpackArgs>) -> Result<CallToolResult, McpError> {
1432 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.container_paths);
1433 send_and_respond!(self, "add_packed_files_from_pack_file_to_animpack", Command::AddPackedFilesFromPackFileToAnimpack(params.0.source_pack_key, params.0.pack_key, params.0.animpack_path, paths))
1434 }
1435
1436 #[tool(description = "Copy files from an AnimPack owned by `anim_pack_key` into the destination pack `pack_key` (the two may differ). The `source` is the DataSource (\"PackFile\", \"GameFiles\", etc.); `anim_pack_key` is only used when it is \"PackFile\". The `animpack_path` is the AnimPack's internal path. The `container_paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"animations/anim.anim\"}].")]
1437 pub async fn add_packed_files_from_animpack(&self, params: Parameters<AddPackedFilesFromAnimpackArgs>) -> Result<CallToolResult, McpError> {
1438 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.container_paths);
1439 send_and_respond!(self, "add_packed_files_from_animpack", Command::AddPackedFilesFromAnimpack(params.0.anim_pack_key, params.0.pack_key, params.0.source, params.0.animpack_path, paths))
1440 }
1441
1442 #[tool(description = "Delete files from the pack identified by `pack_key`. The `paths` is a JSON array of ContainerPath: [{\"File\": \"path/to/file\"}, {\"Folder\": \"path/to/folder\"}].")]
1443 pub async fn delete_packed_files(&self, params: Parameters<ContainerPathsArg>) -> Result<CallToolResult, McpError> {
1444 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1445 send_and_respond!(self, "delete_packed_files", Command::DeletePackedFiles(params.0.pack_key, paths))
1446 }
1447
1448 #[tool(description = "Delete files from an AnimPack in the pack identified by `pack_key`. The `animpack_path` is the AnimPack's internal path. The `container_paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"animations/anim.anim\"}].")]
1449 pub async fn delete_from_animpack(&self, params: Parameters<DeleteFromAnimpackArgs>) -> Result<CallToolResult, McpError> {
1450 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.container_paths);
1451 send_and_respond!(self, "delete_from_animpack", Command::DeleteFromAnimpack(params.0.pack_key, params.0.animpack_path, paths))
1452 }
1453
1454 #[tool(description = "Extract files from the pack identified by `pack_key` to disk. The `source_paths` is a JSON object mapping DataSource to ContainerPath arrays, e.g. {\"PackFile\": [{\"File\": \"db/table/file\"}]}. Set `export_as_tsv: true` to export tables as TSV files.")]
1455 pub async fn extract_packed_files(&self, params: Parameters<ExtractPackedFilesArgs>) -> Result<CallToolResult, McpError> {
1456 let source: BTreeMap<DataSource, Vec<ContainerPath>> = parse_json!(¶ms.0.source_paths);
1457 send_and_respond!(self, "extract_packed_files", Command::ExtractPackedFiles(params.0.pack_key, source, params.0.destination_path, params.0.export_as_tsv))
1458 }
1459
1460 #[tool(description = "Rename files in the pack identified by `pack_key`. The `renames` is a JSON array of [old, new] ContainerPath pairs, e.g. [[{\"File\": \"old/path\"}, {\"File\": \"new/path\"}]].")]
1461 pub async fn rename_packed_files(&self, params: Parameters<RenamePackedFilesArgs>) -> Result<CallToolResult, McpError> {
1462 let renames: Vec<(ContainerPath, ContainerPath)> = parse_json!(¶ms.0.renames);
1463 send_and_respond!(self, "rename_packed_files", Command::RenamePackedFiles(params.0.pack_key, renames))
1464 }
1465
1466 #[tool(description = "Copy files to the internal clipboard. The `paths_by_pack` is a JSON object mapping pack key to ContainerPath arrays, e.g. {\"my_pack.pack\": [{\"File\": \"db/table/file\"}]}. Use `paste_packed_files` to paste afterwards.")]
1467 pub async fn copy_packed_files(&self, params: Parameters<CopyOrCutPackedFilesArgs>) -> Result<CallToolResult, McpError> {
1468 let paths_by_pack: BTreeMap<String, Vec<ContainerPath>> = parse_json!(¶ms.0.paths_by_pack);
1469 send_and_respond!(self, "copy_packed_files", Command::CopyPackedFiles(paths_by_pack))
1470 }
1471
1472 #[tool(description = "Cut files to the internal clipboard. Same as copy, but files will be removed from the source pack on paste. The `paths_by_pack` is a JSON object mapping pack key to ContainerPath arrays. Use `paste_packed_files` to paste afterwards.")]
1473 pub async fn cut_packed_files(&self, params: Parameters<CopyOrCutPackedFilesArgs>) -> Result<CallToolResult, McpError> {
1474 let paths_by_pack: BTreeMap<String, Vec<ContainerPath>> = parse_json!(¶ms.0.paths_by_pack);
1475 send_and_respond!(self, "cut_packed_files", Command::CutPackedFiles(paths_by_pack))
1476 }
1477
1478 #[tool(description = "Paste files from the internal clipboard into the pack identified by `pack_key`. The `destination_path` is the folder path to paste into (empty string for root). Returns the added paths, any cut-deleted paths, and the source pack key.")]
1479 pub async fn paste_packed_files(&self, params: Parameters<PastePackedFilesArgs>) -> Result<CallToolResult, McpError> {
1480 send_and_respond!(self, "paste_packed_files", Command::PastePackedFiles(params.0.pack_key, params.0.destination_path))
1481 }
1482
1483 #[tool(description = "Duplicate files in-place within the same pack. Files are cloned with a numeric suffix to avoid name collisions. The `paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"db/table/file\"}].")]
1484 pub async fn duplicate_packed_files(&self, params: Parameters<DuplicatePackedFilesArgs>) -> Result<CallToolResult, McpError> {
1485 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1486 send_and_respond!(self, "duplicate_packed_files", Command::DuplicatePackedFiles(params.0.pack_key, paths))
1487 }
1488
1489 #[tool(description = "Save an edited decoded file back to the pack identified by `pack_key`. The `path` is the internal path (e.g. \"db/land_units_tables/my_mod\"). The `data` is the modified RFileDecoded JSON (same structure returned by `decode_packed_file`).")]
1490 pub async fn save_packed_file_from_view(&self, params: Parameters<SavePackedFileFromViewArgs>) -> Result<CallToolResult, McpError> {
1491 let data: RFileDecoded = parse_json!(¶ms.0.data);
1492 send_and_respond!(self, "save_packed_file_from_view", Command::SavePackedFileFromView(params.0.pack_key, params.0.path, data))
1493 }
1494
1495 #[tool(description = "Save a file from an external program back to the pack identified by `pack_key`.")]
1496 pub async fn save_packed_file_from_external_view(&self, params: Parameters<SavePackedFileFromExternalViewArgs>) -> Result<CallToolResult, McpError> {
1497 send_and_respond!(self, "save_packed_file_from_external_view", Command::SavePackedFileFromExternalView(params.0.pack_key, params.0.internal_path, params.0.external_path))
1498 }
1499
1500 #[tool(description = "Save files to the pack identified by `pack_key` and optionally optimize afterward. The `files` is a JSON array of RFile objects (as returned by decode/get operations). Set `optimize` to true to remove unchanged data after saving.")]
1501 pub async fn save_packed_files_to_pack_file_and_clean(&self, params: Parameters<SavePackedFilesToPackFileAndCleanArgs>) -> Result<CallToolResult, McpError> {
1502 let files: Vec<RFile> = parse_json!(¶ms.0.files);
1503 send_and_respond!(self, "save_packed_files_to_pack_file_and_clean", Command::SavePackedFilesToPackFileAndClean(params.0.pack_key, files, params.0.optimize))
1504 }
1505
1506 #[tool(description = "Get the raw binary data of a file in the pack identified by `pack_key`.")]
1507 pub async fn get_packed_file_raw_data(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1508 send_and_respond!(self, "get_packed_file_raw_data", Command::GetPackedFileRawData(params.0.pack_key, params.0.value))
1509 }
1510
1511 #[tool(description = "Open a file in the system's default program from the pack identified by `pack_key`. The `source` is the DataSource (\"PackFile\", \"GameFiles\", etc.). The `container_path` is a ContainerPath JSON, e.g. {\"File\": \"db/table/file\"}.")]
1512 pub async fn open_packed_file_in_external_program(&self, params: Parameters<OpenPackedFileInExternalProgramArgs>) -> Result<CallToolResult, McpError> {
1513 let cp: ContainerPath = parse_json!(¶ms.0.container_path);
1514 send_and_respond!(self, "open_packed_file_in_external_program", Command::OpenPackedFileInExternalProgram(params.0.pack_key, params.0.source, cp))
1515 }
1516
1517 #[tool(description = "Open the folder containing the pack identified by `pack_key` in the file manager.")]
1518 pub async fn open_containing_folder(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1519 send_and_respond!(self, "open_containing_folder", Command::OpenContainingFolder(params.0.pack_key))
1520 }
1521
1522 #[tool(description = "Clean the decode cache for the provided paths in the pack identified by `pack_key`. The `paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"db/land_units_tables/my_mod\"}, {\"Folder\": \"db\"}].")]
1523 pub async fn clean_cache(&self, params: Parameters<ContainerPathsArg>) -> Result<CallToolResult, McpError> {
1524 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1525 send_and_respond!(self, "clean_cache", Command::CleanCache(params.0.pack_key, paths))
1526 }
1527
1528 #[tool(description = "Check if a folder exists in the pack identified by `pack_key`.")]
1529 pub async fn folder_exists(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1530 send_and_respond!(self, "folder_exists", Command::FolderExists(params.0.pack_key, params.0.value))
1531 }
1532
1533 #[tool(description = "Check if a file exists in the pack identified by `pack_key`.")]
1534 pub async fn packed_file_exists(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1535 send_and_respond!(self, "packed_file_exists", Command::PackedFileExists(params.0.pack_key, params.0.value))
1536 }
1537
1538 #[tool(description = "Get the info of one or more files in the pack identified by `pack_key`.")]
1539 pub async fn get_packed_files_info(&self, params: Parameters<PackKeyStringsArg>) -> Result<CallToolResult, McpError> {
1540 send_and_respond!(self, "get_packed_files_info", Command::GetPackedFilesInfo(params.0.pack_key, params.0.values))
1541 }
1542
1543 #[tool(description = "Get the info of a single file in the pack identified by `pack_key`.")]
1544 pub async fn get_rfile_info(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1545 send_and_respond!(self, "get_rfile_info", Command::GetRFileInfo(params.0.pack_key, params.0.value))
1546 }
1547
1548 #[tool(description = "Get the currently selected game key.")]
1553 pub async fn get_game_selected(&self) -> Result<CallToolResult, McpError> {
1554 send_and_respond!(self, "get_game_selected", Command::GetGameSelected)
1555 }
1556
1557 #[tool(description = "Set the current game. Valid game keys: pharaoh_dynasties, pharaoh, warhammer_3, troy, three_kingdoms, warhammer_2, warhammer, thrones_of_britannia, attila, rome_2, shogun_2, napoleon, empire, arena. Set rebuild_dependencies to true on first call to load schemas and vanilla data.")]
1558 pub async fn set_game_selected(&self, params: Parameters<SetGameSelectedArgs>) -> Result<CallToolResult, McpError> {
1559 send_and_respond!(self, "set_game_selected", Command::SetGameSelected(params.0.game_name, params.0.rebuild_dependencies))
1560 }
1561
1562 #[tool(description = "Generate the dependencies cache for the selected game. This can take a long time (more than 30 seconds), depending on your CPU and disk read speed. If the client is not careful, it can take enough time that the client may trigger a timeout.")]
1567 pub async fn generate_dependencies_cache(&self) -> Result<CallToolResult, McpError> {
1568 send_and_respond!(self, "generate_dependencies_cache", Command::GenerateDependenciesCache)
1569 }
1570
1571 #[tool(description = "Rebuild dependencies. Pass true for full rebuild, false for mod-specific only.")]
1572 pub async fn rebuild_dependencies(&self, params: Parameters<BoolArg>) -> Result<CallToolResult, McpError> {
1573 send_and_respond!(self, "rebuild_dependencies", Command::RebuildDependencies(params.0.value))
1574 }
1575
1576 #[tool(description = "Check if there is a dependency database loaded. Pass true to ensure AssKit data is included.")]
1577 pub async fn is_there_a_dependency_database(&self, params: Parameters<BoolArg>) -> Result<CallToolResult, McpError> {
1578 send_and_respond!(self, "is_there_a_dependency_database", Command::IsThereADependencyDatabase(params.0.value))
1579 }
1580
1581 #[tool(description = "Get the table names of all DB files in dependency PackFiles.")]
1582 pub async fn get_table_list_from_dependency_pack_file(&self) -> Result<CallToolResult, McpError> {
1583 send_and_respond!(self, "get_table_list_from_dependency_pack_file", Command::GetTableListFromDependencyPackFile)
1584 }
1585
1586 #[tool(description = "Get custom table names (start_pos_, twad_ prefixes) from the schema.")]
1587 pub async fn get_custom_table_list(&self) -> Result<CallToolResult, McpError> {
1588 send_and_respond!(self, "get_custom_table_list", Command::GetCustomTableList)
1589 }
1590
1591 #[tool(description = "Get the version of a table from the dependency database.")]
1592 pub async fn get_table_version_from_dependency_pack_file(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1593 send_and_respond!(self, "get_table_version_from_dependency_pack_file", Command::GetTableVersionFromDependencyPackFile(params.0.value))
1594 }
1595
1596 #[tool(description = "Get the definition of a table from the dependency database.")]
1597 pub async fn get_table_definition_from_dependency_pack_file(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1598 send_and_respond!(self, "get_table_definition_from_dependency_pack_file", Command::GetTableDefinitionFromDependencyPackFile(params.0.value))
1599 }
1600
1601 #[tool(description = "Get table data from dependencies by table name.")]
1602 pub async fn get_tables_from_dependencies(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1603 send_and_respond!(self, "get_tables_from_dependencies", Command::GetTablesFromDependencies(params.0.value))
1604 }
1605
1606 #[tool(description = "Import files from dependencies into the pack identified by `pack_key`. The `paths` is a JSON object mapping DataSource to ContainerPath arrays, e.g. {\"GameFiles\": [{\"File\": \"db/table/file\"}]}.")]
1607 pub async fn import_dependencies_to_open_pack_file(&self, params: Parameters<ImportDependenciesArgs>) -> Result<CallToolResult, McpError> {
1608 let paths: BTreeMap<DataSource, Vec<ContainerPath>> = parse_json!(¶ms.0.paths);
1609 send_and_respond!(self, "import_dependencies_to_open_pack_file", Command::ImportDependenciesToOpenPackFile(params.0.pack_key, paths))
1610 }
1611
1612 #[tool(description = "Get files from all known sources (PackFile, GameFiles, ParentFiles). The `paths` is a JSON array of ContainerPath, e.g. [{\"File\": \"db/land_units_tables/some_file\"}]. Set `lowercase` to true to normalize path casing.")]
1613 pub async fn get_rfiles_from_all_sources(&self, params: Parameters<GetRFilesFromAllSourcesArgs>) -> Result<CallToolResult, McpError> {
1614 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1615 send_and_respond!(self, "get_rfiles_from_all_sources", Command::GetRFilesFromAllSources(paths, params.0.lowercase))
1616 }
1617
1618 #[tool(description = "Get all file names under a path prefix across all data sources (PackFile, GameFiles, ParentFiles). The `path` is a ContainerPath JSON, e.g. {\"Folder\": \"db/land_units_tables\"} to list all files under that folder.")]
1619 pub async fn get_packed_files_names_starting_with_path_from_all_sources(&self, params: Parameters<ContainerPathArg>) -> Result<CallToolResult, McpError> {
1620 let path: ContainerPath = parse_json!(¶ms.0.path);
1621 send_and_respond!(self, "get_packed_files_names_starting_with_path_from_all_sources", Command::GetPackedFilesNamesStartingWitPathFromAllSources(path))
1622 }
1623
1624 #[tool(description = "Get local art set IDs from campaign_character_arts_tables in the pack identified by `pack_key`.")]
1625 pub async fn local_art_set_ids(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1626 send_and_respond!(self, "local_art_set_ids", Command::LocalArtSetIds(params.0.pack_key))
1627 }
1628
1629 #[tool(description = "Get art set IDs from dependencies' campaign_character_arts_tables.")]
1630 pub async fn dependencies_art_set_ids(&self) -> Result<CallToolResult, McpError> {
1631 send_and_respond!(self, "dependencies_art_set_ids", Command::DependenciesArtSetIds)
1632 }
1633
1634 #[tool(description = "Run a global search across the pack identified by `pack_key`. The `search` is a GlobalSearch JSON with fields: pattern (string), replace_text (string), case_sensitive (bool), use_regex (bool), search_on ({db: bool, loc: bool, text: bool, ...}), sources ([{\"Pack\": \"key\"}]), game_key (string). See the `rpfm://examples/global_search` resource for a full example.")]
1639 pub async fn global_search(&self, params: Parameters<GlobalSearchArgs>) -> Result<CallToolResult, McpError> {
1640 let search = parse_json!(¶ms.0.search);
1641 send_and_respond!(self, "global_search", Command::GlobalSearch(params.0.pack_key, search))
1642 }
1643
1644 #[tool(description = "Replace specific matches in a global search for the pack identified by `pack_key`. The `search` is the same GlobalSearch JSON used in `global_search` (see `rpfm://examples/global_search` resource). The `matches` is a JSON array of MatchHolder objects from the search results — include only the matches you want to replace.")]
1645 pub async fn global_search_replace_matches(&self, params: Parameters<GlobalSearchReplaceMatchesArgs>) -> Result<CallToolResult, McpError> {
1646 let search = parse_json!(¶ms.0.search);
1647 let matches = parse_json!(¶ms.0.matches);
1648 send_and_respond!(self, "global_search_replace_matches", Command::GlobalSearchReplaceMatches(params.0.pack_key, search, matches))
1649 }
1650
1651 #[tool(description = "Replace all matches in a global search for the pack identified by `pack_key`. The `search` is a GlobalSearch JSON with the `replace_text` field set to the replacement string. See `rpfm://examples/global_search` resource for the full structure.")]
1652 pub async fn global_search_replace_all(&self, params: Parameters<GlobalSearchArgs>) -> Result<CallToolResult, McpError> {
1653 let search = parse_json!(¶ms.0.search);
1654 send_and_respond!(self, "global_search_replace_all", Command::GlobalSearchReplaceAll(params.0.pack_key, search))
1655 }
1656
1657 #[tool(description = "Find all references to a value in the pack identified by `pack_key`. The `reference_map` is a JSON object mapping table names to column name arrays, e.g. {\"land_units_tables\": [\"key\", \"unit\"]}. The `value` is the string to search for across those columns.")]
1658 pub async fn search_references(&self, params: Parameters<SearchReferencesArgs>) -> Result<CallToolResult, McpError> {
1659 let map: HashMap<String, Vec<String>> = parse_json!(¶ms.0.reference_map);
1660 send_and_respond!(self, "search_references", Command::SearchReferences(params.0.pack_key, map, params.0.value))
1661 }
1662
1663 #[tool(description = "Get valid reference values for columns in a table definition for the pack identified by `pack_key`. The `definition` is a Definition JSON (as returned by `get_table_definition_from_dependency_pack_file`). Set `force` to true to regenerate cached reference data.")]
1664 pub async fn get_reference_data_from_definition(&self, params: Parameters<GetReferenceDataFromDefinitionArgs>) -> Result<CallToolResult, McpError> {
1665 let def = parse_json!(¶ms.0.definition);
1666 send_and_respond!(self, "get_reference_data_from_definition", Command::GetReferenceDataFromDefinition(params.0.pack_key, params.0.table_name, def, params.0.force))
1667 }
1668
1669 #[tool(description = "Go to the definition of a reference in the pack identified by `pack_key`. Provide table name, column name, and values to search.")]
1670 pub async fn go_to_definition(&self, params: Parameters<GoToDefinitionArgs>) -> Result<CallToolResult, McpError> {
1671 send_and_respond!(self, "go_to_definition", Command::GoToDefinition(params.0.pack_key, params.0.table_name, params.0.column_name, params.0.values))
1672 }
1673
1674 #[tool(description = "Go to a loc key's location in the pack identified by `pack_key`.")]
1675 pub async fn go_to_loc(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1676 send_and_respond!(self, "go_to_loc", Command::GoToLoc(params.0.pack_key, params.0.value))
1677 }
1678
1679 #[tool(description = "Get the source data of a loc key in the pack identified by `pack_key`.")]
1680 pub async fn get_source_data_from_loc_key(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1681 send_and_respond!(self, "get_source_data_from_loc_key", Command::GetSourceDataFromLocKey(params.0.pack_key, params.0.value))
1682 }
1683
1684 #[tool(description = "Save the provided schema to disk. The `schema` is the full Schema JSON object (as returned by `get_schema`). Use this after modifying definitions or applying patches.")]
1689 pub async fn save_schema(&self, params: Parameters<SaveSchemaArgs>) -> Result<CallToolResult, McpError> {
1690 let schema = parse_json!(¶ms.0.schema);
1691 send_and_respond!(self, "save_schema", Command::SaveSchema(schema))
1692 }
1693
1694 #[tool(description = "Update the currently loaded schema with data from the game's Assembly Kit.")]
1695 pub async fn update_current_schema_from_asskit(&self) -> Result<CallToolResult, McpError> {
1696 send_and_respond!(self, "update_current_schema_from_asskit", Command::UpdateCurrentSchemaFromAssKit)
1697 }
1698
1699 #[tool(description = "Update schemas from the remote repository.")]
1700 pub async fn update_schemas(&self) -> Result<CallToolResult, McpError> {
1701 send_and_respond!(self, "update_schemas", Command::UpdateSchemas)
1702 }
1703
1704 #[tool(description = "Check if a schema is currently loaded.")]
1705 pub async fn is_schema_loaded(&self) -> Result<CallToolResult, McpError> {
1706 send_and_respond!(self, "is_schema_loaded", Command::IsSchemaLoaded)
1707 }
1708
1709 #[tool(description = "Get the current schema.")]
1710 pub async fn get_schema(&self) -> Result<CallToolResult, McpError> {
1711 send_and_respond!(self, "get_schema", Command::Schema)
1712 }
1713
1714 #[tool(description = "Get all definitions for a table name.")]
1715 pub async fn definitions_by_table_name(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1716 send_and_respond!(self, "definitions_by_table_name", Command::DefinitionsByTableName(params.0.value))
1717 }
1718
1719 #[tool(description = "Get a specific definition by table name and version.")]
1720 pub async fn definition_by_table_name_and_version(&self, params: Parameters<StringI32Args>) -> Result<CallToolResult, McpError> {
1721 send_and_respond!(self, "definition_by_table_name_and_version", Command::DefinitionByTableNameAndVersion(params.0.name, params.0.version))
1722 }
1723
1724 #[tool(description = "Delete a definition by table name and version.")]
1725 pub async fn delete_definition(&self, params: Parameters<StringI32Args>) -> Result<CallToolResult, McpError> {
1726 send_and_respond!(self, "delete_definition", Command::DeleteDefinition(params.0.name, params.0.version))
1727 }
1728
1729 #[tool(description = "Get columns from other tables that reference the given table's definition. The `definition` is a Definition JSON (as returned by `get_table_definition_from_dependency_pack_file` or `definitions_by_table_name`).")]
1730 pub async fn referencing_columns_for_definition(&self, params: Parameters<ReferencingColumnsForDefinitionArgs>) -> Result<CallToolResult, McpError> {
1731 let def = parse_json!(¶ms.0.definition);
1732 send_and_respond!(self, "referencing_columns_for_definition", Command::ReferencingColumnsForDefinition(params.0.table_name, def))
1733 }
1734
1735 #[tool(description = "Get the processed fields from a definition with bitwise expansion and enum conversions applied (useful for display). The `definition` is a Definition JSON (as returned by `get_table_definition_from_dependency_pack_file`).")]
1736 pub async fn fields_processed(&self, params: Parameters<DefinitionArg>) -> Result<CallToolResult, McpError> {
1737 let def = parse_json!(¶ms.0.definition);
1738 send_and_respond!(self, "fields_processed", Command::FieldsProcessed(def))
1739 }
1740
1741 #[tool(description = "Save local schema patches to customize column metadata without modifying the upstream schema. The `patches` is a JSON object mapping table names to DefinitionPatch objects, e.g. {\"land_units_tables\": {\"field_patches\": {...}}}.")]
1742 pub async fn save_local_schema_patch(&self, params: Parameters<SchemaPatchArgs>) -> Result<CallToolResult, McpError> {
1743 let patches = parse_json!(¶ms.0.patches);
1744 send_and_respond!(self, "save_local_schema_patch", Command::SaveLocalSchemaPatch(patches))
1745 }
1746
1747 #[tool(description = "Remove local schema patches for a table.")]
1748 pub async fn remove_local_schema_patches_for_table(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1749 send_and_respond!(self, "remove_local_schema_patches_for_table", Command::RemoveLocalSchemaPatchesForTable(params.0.value))
1750 }
1751
1752 #[tool(description = "Remove local schema patches for a specific field in a table.")]
1753 pub async fn remove_local_schema_patches_for_table_and_field(&self, params: Parameters<SettingsSetStringArgs>) -> Result<CallToolResult, McpError> {
1754 send_and_respond!(self, "remove_local_schema_patches_for_table_and_field", Command::RemoveLocalSchemaPatchesForTableAndField(params.0.key, params.0.value))
1755 }
1756
1757 #[tool(description = "Import a schema patch from an external source. The `patches` is a JSON object mapping table names to DefinitionPatch objects (same format as `save_local_schema_patch`).")]
1758 pub async fn import_schema_patch(&self, params: Parameters<SchemaPatchArgs>) -> Result<CallToolResult, McpError> {
1759 let patches = parse_json!(¶ms.0.patches);
1760 send_and_respond!(self, "import_schema_patch", Command::ImportSchemaPatch(patches))
1761 }
1762
1763 #[tool(description = "Merge multiple compatible tables into one in the pack identified by `pack_key`. The `paths` is a JSON array of ContainerPath for the tables to merge, e.g. [{\"File\": \"db/land_units_tables/table1\"}, {\"File\": \"db/land_units_tables/table2\"}]. The `merged_path` is the destination path. Set `delete_source` to true to remove the original files.")]
1768 pub async fn merge_files(&self, params: Parameters<MergeFilesArgs>) -> Result<CallToolResult, McpError> {
1769 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1770 send_and_respond!(self, "merge_files", Command::MergeFiles(params.0.pack_key, paths, params.0.merged_path, params.0.delete_source))
1771 }
1772
1773 #[tool(description = "Update a table to the latest schema version in the pack identified by `pack_key`. The `value` is a ContainerPath JSON, e.g. {\"File\": \"db/land_units_tables/my_mod\"}.")]
1774 pub async fn update_table(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1775 let path: ContainerPath = parse_json!(¶ms.0.value);
1776 send_and_respond!(self, "update_table", Command::UpdateTable(params.0.pack_key, path))
1777 }
1778
1779 #[tool(description = "Trigger a cascade edition on all referenced data in the pack identified by `pack_key`. When a key value changes, this propagates the change to all referencing tables. The `definition` is a Definition JSON for the source table. The `changes` is a JSON array of [field, old_value, new_value] tuples, e.g. [[field_json, \"old_key\", \"new_key\"]].")]
1780 pub async fn cascade_edition(&self, params: Parameters<CascadeEditionArgs>) -> Result<CallToolResult, McpError> {
1781 let def = parse_json!(¶ms.0.definition);
1782 let changes = parse_json!(¶ms.0.changes);
1783 send_and_respond!(self, "cascade_edition", Command::CascadeEdition(params.0.pack_key, params.0.table_name, def, changes))
1784 }
1785
1786 #[tool(description = "Get table paths by table name from the pack identified by `pack_key`.")]
1787 pub async fn get_tables_by_table_name(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1788 send_and_respond!(self, "get_tables_by_table_name", Command::GetTablesByTableName(params.0.pack_key, params.0.value))
1789 }
1790
1791 #[tool(description = "Add keys to the key_deletes table in the pack identified by `pack_key`.")]
1792 pub async fn add_keys_to_key_deletes(&self, params: Parameters<AddKeysToKeyDeletesArgs>) -> Result<CallToolResult, McpError> {
1793 send_and_respond!(self, "add_keys_to_key_deletes", Command::AddKeysToKeyDeletes(params.0.pack_key, params.0.table_file_name, params.0.key_table_name, params.0.keys))
1794 }
1795
1796 #[tool(description = "Export a table from the pack identified by `pack_key` to a TSV file.")]
1797 pub async fn export_tsv(&self, params: Parameters<TsvExportArgs>) -> Result<CallToolResult, McpError> {
1798 send_and_respond!(self, "export_tsv", Command::ExportTSV(params.0.pack_key, params.0.table_path, params.0.tsv_path, DataSource::PackFile))
1799 }
1800
1801 #[tool(description = "Import a TSV file to a table in the pack identified by `pack_key`.")]
1802 pub async fn import_tsv(&self, params: Parameters<TsvImportArgs>) -> Result<CallToolResult, McpError> {
1803 send_and_respond!(self, "import_tsv", Command::ImportTSV(params.0.pack_key, params.0.table_path, params.0.tsv_path))
1804 }
1805
1806 #[tool(description = "Run a full diagnostics check over all open packs.")]
1811 pub async fn diagnostics_check(&self, params: Parameters<DiagnosticsCheckArgs>) -> Result<CallToolResult, McpError> {
1812 send_and_respond!(self, "diagnostics_check", Command::DiagnosticsCheck(params.0.ignored, params.0.check_ak_only_refs))
1813 }
1814
1815 #[tool(description = "Update diagnostics incrementally for changed files across all open packs. The `diagnostics` is the Diagnostics JSON from a previous `diagnostics_check` call. The `paths` is a JSON array of ContainerPath for the files that changed, e.g. [{\"File\": \"db/land_units_tables/my_mod\"}].")]
1816 pub async fn diagnostics_update(&self, params: Parameters<DiagnosticsUpdateArgs>) -> Result<CallToolResult, McpError> {
1817 let diag = parse_json!(¶ms.0.diagnostics);
1818 let paths: Vec<ContainerPath> = parse_json!(¶ms.0.paths);
1819 send_and_respond!(self, "diagnostics_update", Command::DiagnosticsUpdate(diag, paths, params.0.check_ak_only_refs))
1820 }
1821
1822 #[tool(description = "Add a line to the ignored diagnostics list for the pack identified by `pack_key`.")]
1823 pub async fn add_line_to_pack_ignored_diagnostics(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1824 send_and_respond!(self, "add_line_to_pack_ignored_diagnostics", Command::AddLineToPackIgnoredDiagnostics(params.0.pack_key, params.0.value))
1825 }
1826
1827 #[tool(description = "Export missing table definitions for the pack identified by `pack_key` to a file (for debugging).")]
1828 pub async fn get_missing_definitions(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
1829 send_and_respond!(self, "get_missing_definitions", Command::GetMissingDefinitions(params.0.pack_key))
1830 }
1831
1832 #[tool(description = "Get all notes under a path in the pack identified by `pack_key`.")]
1837 pub async fn notes_for_path(&self, params: Parameters<PackKeyStringArg>) -> Result<CallToolResult, McpError> {
1838 send_and_respond!(self, "notes_for_path", Command::NotesForPath(params.0.pack_key, params.0.value))
1839 }
1840
1841 #[tool(description = "Add a note to the pack identified by `pack_key`. The `note` is a Note JSON object with fields: path (string — the file or folder path to attach the note to), id (u64), text (string — the note content).")]
1842 pub async fn add_note(&self, params: Parameters<AddNoteArgs>) -> Result<CallToolResult, McpError> {
1843 let note = parse_json!(¶ms.0.note);
1844 send_and_respond!(self, "add_note", Command::AddNote(params.0.pack_key, note))
1845 }
1846
1847 #[tool(description = "Delete a note by path and ID in the pack identified by `pack_key`.")]
1848 pub async fn delete_note(&self, params: Parameters<DeleteNoteArgs>) -> Result<CallToolResult, McpError> {
1849 send_and_respond!(self, "delete_note", Command::DeleteNote(params.0.pack_key, params.0.path, params.0.id))
1850 }
1851
1852 #[tool(description = "Optimize the pack identified by `pack_key` by removing unchanged/duplicate data. The `options` is an OptimizerOptions JSON with boolean fields: pack_remove_itm_files, table_remove_duplicated_entries, table_remove_itm_entries, table_remove_itnr_entries, table_remove_empty_file, db_optimize_datacored_tables, etc. See the `rpfm://examples/optimizer_options` resource for all fields.")]
1857 pub async fn optimize_pack_file(&self, params: Parameters<OptimizePackFileArgs>) -> Result<CallToolResult, McpError> {
1858 let options = parse_json!(¶ms.0.options);
1859 send_and_respond!(self, "optimize_pack_file", Command::OptimizePackFile(params.0.pack_key, options))
1860 }
1861
1862 #[tool(description = "Get the default optimizer options.")]
1863 pub async fn get_optimizer_options(&self) -> Result<CallToolResult, McpError> {
1864 send_and_respond!(self, "get_optimizer_options", Command::OptimizerOptions)
1865 }
1866
1867 #[tool(description = "Check if there is an RPFM update available.")]
1872 pub async fn check_updates(&self) -> Result<CallToolResult, McpError> {
1873 send_and_respond!(self, "check_updates", Command::CheckUpdates)
1874 }
1875
1876 #[tool(description = "Check if there is a schema update available.")]
1877 pub async fn check_schema_updates(&self) -> Result<CallToolResult, McpError> {
1878 send_and_respond!(self, "check_schema_updates", Command::CheckSchemaUpdates)
1879 }
1880
1881 #[tool(description = "Check for Lua autogen updates.")]
1882 pub async fn check_lua_autogen_updates(&self) -> Result<CallToolResult, McpError> {
1883 send_and_respond!(self, "check_lua_autogen_updates", Command::CheckLuaAutogenUpdates)
1884 }
1885
1886 #[tool(description = "Check for Empire/Napoleon Assembly Kit updates.")]
1887 pub async fn check_empire_and_napoleon_ak_updates(&self) -> Result<CallToolResult, McpError> {
1888 send_and_respond!(self, "check_empire_and_napoleon_ak_updates", Command::CheckEmpireAndNapoleonAKUpdates)
1889 }
1890
1891 #[tool(description = "Check for translation updates.")]
1892 pub async fn check_translations_updates(&self) -> Result<CallToolResult, McpError> {
1893 send_and_respond!(self, "check_translations_updates", Command::CheckTranslationsUpdates)
1894 }
1895
1896 #[tool(description = "Update the Lua autogen repository.")]
1897 pub async fn update_lua_autogen(&self) -> Result<CallToolResult, McpError> {
1898 send_and_respond!(self, "update_lua_autogen", Command::UpdateLuaAutogen)
1899 }
1900
1901 #[tool(description = "Update the program to the latest version.")]
1902 pub async fn update_main_program(&self) -> Result<CallToolResult, McpError> {
1903 send_and_respond!(self, "update_main_program", Command::UpdateMainProgram)
1904 }
1905
1906 #[tool(description = "Update the Empire/Napoleon Assembly Kit files.")]
1907 pub async fn update_empire_and_napoleon_ak(&self) -> Result<CallToolResult, McpError> {
1908 send_and_respond!(self, "update_empire_and_napoleon_ak", Command::UpdateEmpireAndNapoleonAK)
1909 }
1910
1911 #[tool(description = "Update the translations repository.")]
1912 pub async fn update_translations(&self) -> Result<CallToolResult, McpError> {
1913 send_and_respond!(self, "update_translations", Command::UpdateTranslations)
1914 }
1915
1916 #[tool(description = "Get a boolean setting value by key.")]
1921 pub async fn settings_get_bool(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1922 send_and_respond!(self, "settings_get_bool", Command::SettingsGetBool(params.0.value))
1923 }
1924
1925 #[tool(description = "Get an i32 setting value by key.")]
1926 pub async fn settings_get_i32(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1927 send_and_respond!(self, "settings_get_i32", Command::SettingsGetI32(params.0.value))
1928 }
1929
1930 #[tool(description = "Get an f32 setting value by key.")]
1931 pub async fn settings_get_f32(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1932 send_and_respond!(self, "settings_get_f32", Command::SettingsGetF32(params.0.value))
1933 }
1934
1935 #[tool(description = "Get a string setting value by key.")]
1936 pub async fn settings_get_string(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1937 send_and_respond!(self, "settings_get_string", Command::SettingsGetString(params.0.value))
1938 }
1939
1940 #[tool(description = "Get a PathBuf setting value by key.")]
1941 pub async fn settings_get_path_buf(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1942 send_and_respond!(self, "settings_get_path_buf", Command::SettingsGetPathBuf(params.0.value))
1943 }
1944
1945 #[tool(description = "Get a Vec<String> setting value by key.")]
1946 pub async fn settings_get_vec_string(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1947 send_and_respond!(self, "settings_get_vec_string", Command::SettingsGetVecString(params.0.value))
1948 }
1949
1950 #[tool(description = "Get a raw bytes setting value by key.")]
1951 pub async fn settings_get_vec_raw(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
1952 send_and_respond!(self, "settings_get_vec_raw", Command::SettingsGetVecRaw(params.0.value))
1953 }
1954
1955 #[tool(description = "Get all settings at once (bool, i32, f32, string, raw_data, and vec_string maps).")]
1956 pub async fn settings_get_all(&self) -> Result<CallToolResult, McpError> {
1957 send_and_respond!(self, "settings_get_all", Command::SettingsGetAll)
1958 }
1959
1960 #[tool(description = "Set a boolean setting value.")]
1965 pub async fn settings_set_bool(&self, params: Parameters<SettingsSetBoolArgs>) -> Result<CallToolResult, McpError> {
1966 send_and_respond!(self, "settings_set_bool", Command::SettingsSetBool(params.0.key, params.0.value))
1967 }
1968
1969 #[tool(description = "Set an i32 setting value.")]
1970 pub async fn settings_set_i32(&self, params: Parameters<SettingsSetI32Args>) -> Result<CallToolResult, McpError> {
1971 send_and_respond!(self, "settings_set_i32", Command::SettingsSetI32(params.0.key, params.0.value))
1972 }
1973
1974 #[tool(description = "Set an f32 setting value.")]
1975 pub async fn settings_set_f32(&self, params: Parameters<SettingsSetF32Args>) -> Result<CallToolResult, McpError> {
1976 send_and_respond!(self, "settings_set_f32", Command::SettingsSetF32(params.0.key, params.0.value))
1977 }
1978
1979 #[tool(description = "Set a string setting value.")]
1980 pub async fn settings_set_string(&self, params: Parameters<SettingsSetStringArgs>) -> Result<CallToolResult, McpError> {
1981 send_and_respond!(self, "settings_set_string", Command::SettingsSetString(params.0.key, params.0.value))
1982 }
1983
1984 #[tool(description = "Set a PathBuf setting value.")]
1985 pub async fn settings_set_path_buf(&self, params: Parameters<SettingsSetPathBufArgs>) -> Result<CallToolResult, McpError> {
1986 send_and_respond!(self, "settings_set_path_buf", Command::SettingsSetPathBuf(params.0.key, params.0.value))
1987 }
1988
1989 #[tool(description = "Set a Vec<String> setting value.")]
1990 pub async fn settings_set_vec_string(&self, params: Parameters<SettingsSetVecStringArgs>) -> Result<CallToolResult, McpError> {
1991 send_and_respond!(self, "settings_set_vec_string", Command::SettingsSetVecString(params.0.key, params.0.value))
1992 }
1993
1994 #[tool(description = "Set a raw bytes setting value.")]
1995 pub async fn settings_set_vec_raw(&self, params: Parameters<SettingsSetVecRawArgs>) -> Result<CallToolResult, McpError> {
1996 send_and_respond!(self, "settings_set_vec_raw", Command::SettingsSetVecRaw(params.0.key, params.0.value))
1997 }
1998
1999 #[tool(description = "Backup the current settings to memory.")]
2000 pub async fn backup_settings(&self) -> Result<CallToolResult, McpError> {
2001 send_and_respond!(self, "backup_settings", Command::BackupSettings)
2002 }
2003
2004 #[tool(description = "Clear all settings and reset to defaults.")]
2005 pub async fn clear_settings(&self) -> Result<CallToolResult, McpError> {
2006 send_and_respond!(self, "clear_settings", Command::ClearSettings)
2007 }
2008
2009 #[tool(description = "Restore settings from the backup.")]
2010 pub async fn restore_backup_settings(&self) -> Result<CallToolResult, McpError> {
2011 send_and_respond!(self, "restore_backup_settings", Command::RestoreBackupSettings)
2012 }
2013
2014 #[tool(description = "Get the config path.")]
2019 pub async fn config_path(&self) -> Result<CallToolResult, McpError> {
2020 send_and_respond!(self, "config_path", Command::ConfigPath)
2021 }
2022
2023 #[tool(description = "Get the Assembly Kit path for the current game.")]
2024 pub async fn assembly_kit_path(&self) -> Result<CallToolResult, McpError> {
2025 send_and_respond!(self, "assembly_kit_path", Command::AssemblyKitPath)
2026 }
2027
2028 #[tool(description = "Get the backup autosave path.")]
2029 pub async fn backup_autosave_path(&self) -> Result<CallToolResult, McpError> {
2030 send_and_respond!(self, "backup_autosave_path", Command::BackupAutosavePath)
2031 }
2032
2033 #[tool(description = "Get the old Assembly Kit data path.")]
2034 pub async fn old_ak_data_path(&self) -> Result<CallToolResult, McpError> {
2035 send_and_respond!(self, "old_ak_data_path", Command::OldAkDataPath)
2036 }
2037
2038 #[tool(description = "Get the schemas path.")]
2039 pub async fn schemas_path(&self) -> Result<CallToolResult, McpError> {
2040 send_and_respond!(self, "schemas_path", Command::SchemasPath)
2041 }
2042
2043 #[tool(description = "Get the table profiles path.")]
2044 pub async fn table_profiles_path(&self) -> Result<CallToolResult, McpError> {
2045 send_and_respond!(self, "table_profiles_path", Command::TableProfilesPath)
2046 }
2047
2048 #[tool(description = "Get the translations local path.")]
2049 pub async fn translations_local_path(&self) -> Result<CallToolResult, McpError> {
2050 send_and_respond!(self, "translations_local_path", Command::TranslationsLocalPath)
2051 }
2052
2053 #[tool(description = "Get the dependencies cache path.")]
2054 pub async fn dependencies_cache_path(&self) -> Result<CallToolResult, McpError> {
2055 send_and_respond!(self, "dependencies_cache_path", Command::DependenciesCachePath)
2056 }
2057
2058 #[tool(description = "Clear a config path.")]
2059 pub async fn settings_clear_path(&self, params: Parameters<PathArg>) -> Result<CallToolResult, McpError> {
2060 send_and_respond!(self, "settings_clear_path", Command::SettingsClearPath(params.0.path))
2061 }
2062
2063 #[tool(description = "Get the info about the pack identified by `pack_key` and the list of files it contains.")]
2068 pub async fn open_pack_info(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2069 send_and_respond!(self, "open_pack_info", Command::GetPackFileDataForTreeView(params.0.pack_key))
2070 }
2071
2072 #[tool(description = "Initialize a MyMod folder for mod development.")]
2073 pub async fn initialize_my_mod_folder(&self, params: Parameters<InitializeMyModFolderArgs>) -> Result<CallToolResult, McpError> {
2074 send_and_respond!(self, "initialize_my_mod_folder", Command::InitializeMyModFolder(params.0.name, params.0.game, params.0.sublime, params.0.vscode, params.0.gitignore))
2075 }
2076
2077 #[tool(description = "Live export the pack identified by `pack_key` to the game folder for testing.")]
2078 pub async fn live_export(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2079 send_and_respond!(self, "live_export", Command::LiveExport(params.0.pack_key))
2080 }
2081
2082 #[tool(description = "Patch the SiegeAI of a Siege Map in the pack identified by `pack_key` for Warhammer games.")]
2083 pub async fn patch_siege_ai(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2084 send_and_respond!(self, "patch_siege_ai", Command::PatchSiegeAI(params.0.pack_key))
2085 }
2086
2087 #[tool(description = "Pack map tiles into the pack identified by `pack_key`. The `tile_maps` is a list of tile map file paths on disk. The `tiles` is a JSON array of [path, name] pairs, e.g. [[\"/path/to/tile\", \"tile_name\"]].")]
2088 pub async fn pack_map(&self, params: Parameters<PackMapArgs>) -> Result<CallToolResult, McpError> {
2089 let tiles: Vec<(PathBuf, String)> = parse_json!(¶ms.0.tiles);
2090 send_and_respond!(self, "pack_map", Command::PackMap(params.0.pack_key, params.0.tile_maps, tiles))
2091 }
2092
2093 #[tool(description = "Generate all missing loc entries for the pack identified by `pack_key`.")]
2094 pub async fn generate_missing_loc_data(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2095 send_and_respond!(self, "generate_missing_loc_data", Command::GenerateMissingLocData(params.0.pack_key))
2096 }
2097
2098 #[tool(description = "Get pack translation data for a language from the pack identified by `pack_key`.")]
2099 pub async fn get_pack_translation(&self, params: Parameters<GetPackTranslationArgs>) -> Result<CallToolResult, McpError> {
2100 send_and_respond!(self, "get_pack_translation", Command::GetPackTranslation(params.0.pack_key, params.0.language))
2101 }
2102
2103 #[tool(description = "Get campaign IDs for starpos building in the pack identified by `pack_key`.")]
2104 pub async fn build_starpos_get_campaign_ids(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2105 send_and_respond!(self, "build_starpos_get_campaign_ids", Command::BuildStarposGetCampaingIds(params.0.pack_key))
2106 }
2107
2108 #[tool(description = "Check if victory conditions file exists for starpos building in the pack identified by `pack_key`.")]
2109 pub async fn build_starpos_check_victory_conditions(&self, params: Parameters<PackKeyArg>) -> Result<CallToolResult, McpError> {
2110 send_and_respond!(self, "build_starpos_check_victory_conditions", Command::BuildStarposCheckVictoryConditions(params.0.pack_key))
2111 }
2112
2113 #[tool(description = "Build starpos (pre-processing step) for the pack identified by `pack_key`.")]
2114 pub async fn build_starpos(&self, params: Parameters<BuildStarposArgs>) -> Result<CallToolResult, McpError> {
2115 send_and_respond!(self, "build_starpos", Command::BuildStarpos(params.0.pack_key, params.0.campaign_id, params.0.process_hlp_spd))
2116 }
2117
2118 #[tool(description = "Build starpos (post-processing step) for the pack identified by `pack_key`.")]
2119 pub async fn build_starpos_post(&self, params: Parameters<BuildStarposArgs>) -> Result<CallToolResult, McpError> {
2120 send_and_respond!(self, "build_starpos_post", Command::BuildStarposPost(params.0.pack_key, params.0.campaign_id, params.0.process_hlp_spd))
2121 }
2122
2123 #[tool(description = "Clean up starpos temporary files for the pack identified by `pack_key`.")]
2124 pub async fn build_starpos_cleanup(&self, params: Parameters<BuildStarposArgs>) -> Result<CallToolResult, McpError> {
2125 send_and_respond!(self, "build_starpos_cleanup", Command::BuildStarposCleanup(params.0.pack_key, params.0.campaign_id, params.0.process_hlp_spd))
2126 }
2127
2128 #[tool(description = "Update animation IDs with an offset in the pack identified by `pack_key`.")]
2129 pub async fn update_anim_ids(&self, params: Parameters<UpdateAnimIdsArgs>) -> Result<CallToolResult, McpError> {
2130 send_and_respond!(self, "update_anim_ids", Command::UpdateAnimIds(params.0.pack_key, params.0.starting_id, params.0.offset))
2131 }
2132
2133 #[tool(description = "Get animation paths by skeleton name.")]
2134 pub async fn get_anim_paths_by_skeleton_name(&self, params: Parameters<StringArg>) -> Result<CallToolResult, McpError> {
2135 send_and_respond!(self, "get_anim_paths_by_skeleton_name", Command::GetAnimPathsBySkeletonName(params.0.value))
2136 }
2137
2138 #[tool(description = "Export a RigidModel to glTF format. The `rigid_model` is a RigidModel JSON object (as returned by decoding a .rigid_model_v2 file with `decode_packed_file`). The `output_path` is the destination file path on disk.")]
2139 pub async fn export_rigid_to_gltf(&self, params: Parameters<ExportRigidToGltfArgs>) -> Result<CallToolResult, McpError> {
2140 let rigid = parse_json!(¶ms.0.rigid_model);
2141 send_and_respond!(self, "export_rigid_to_gltf", Command::ExportRigidToGltf(rigid, params.0.output_path))
2142 }
2143
2144 #[tool(description = "Change the format of a ca_vp8 video file in the pack identified by `pack_key`. Valid formats: \"CaVp8\" (CA custom VP8) or \"Ivf\" (standard VP8 IVF).")]
2145 pub async fn set_video_format(&self, params: Parameters<SetVideoFormatArgs>) -> Result<CallToolResult, McpError> {
2146 let format = parse_json!(¶ms.0.format);
2147 send_and_respond!(self, "set_video_format", Command::SetVideoFormat(params.0.pack_key, params.0.path, format))
2148 }
2149
2150 #[tool(description = "List all currently open packs with their keys and metadata. Use this to get valid pack_key values for other tools.")]
2155 pub async fn list_open_packs(&self) -> Result<CallToolResult, McpError> {
2156 send_and_respond!(self, "list_open_packs", Command::ListOpenPacks)
2157 }
2158
2159 #[tool(description = "Close all currently open packs without saving. Any unsaved changes will be lost.")]
2164 pub async fn close_all_packs(&self) -> Result<CallToolResult, McpError> {
2165 send_and_respond!(self, "close_all_packs", Command::CloseAllPacks)
2166 }
2167
2168}
2169
2170#[prompt_router]
2175impl McpServer {
2176
2177 #[prompt(name = "open_and_inspect_pack", description = "Walk through opening a PackFile and inspecting its contents.")]
2178 pub async fn open_and_inspect_pack(&self) -> Vec<PromptMessage> {
2179 vec![PromptMessage::new_text(
2180 PromptMessageRole::User,
2181 "\
2182You are an assistant helping the user inspect a Total War PackFile using the RPFM MCP server.
2183
2184Follow these steps in order:
2185
21861. **Open the pack** – Call `open_packfiles` with the filesystem path(s) the user provides.
2187 The response contains one or more pack keys; remember them for subsequent calls.
2188
21892. **Select the game** – Call `set_game_selected` with the correct game key (e.g. `\"warhammer_3\"`)
2190 and `rebuild_dependencies: true` so that schemas and dependency data are loaded.
2191
21923. **List pack contents** – Call `open_pack_info` with the pack key to get the full file tree.
2193 Present the tree to the user in a readable format.
2194
21954. **Decode specific files** – When the user asks about a file, call `decode_packed_file` with the
2196 pack key, the internal path (e.g. `\"db/land_units_tables/my_table\"`), and
2197 `source: \"PackFile\"`. The decoded JSON will contain the table rows, schema, etc.
2198
21995. **Inspect metadata** – Use `get_pack_settings`, `get_pack_file_name`, or
2200 `get_dependency_pack_files_list` to answer questions about the pack itself.
2201
2202Important notes:
2203- Always call `list_open_packs` if you are unsure which pack key to use.
2204- If a file fails to decode, check `is_schema_loaded`; if false, call `update_schemas` first.
2205- When done, optionally call `close_pack` to free resources.
2206",
2207 )]
2208 }
2209
2210 #[prompt(name = "edit_db_table", description = "Guide for reading, modifying, and saving a DB table inside a pack.")]
2211 pub async fn edit_db_table(&self) -> Vec<PromptMessage> {
2212 vec![PromptMessage::new_text(
2213 PromptMessageRole::User,
2214 "\
2215You are an assistant helping the user edit a DB table inside a Total War PackFile.
2216
2217Workflow:
2218
22191. **Open the pack** – `open_packfiles` → note the `pack_key`.
22202. **Set the game** – `set_game_selected` with `rebuild_dependencies: true`.
22213. **Decode the table** – `decode_packed_file` with the DB path
2222 (e.g. `\"db/unit_stats_land_tables/my_table\"`) and `source: \"PackFile\"`.
2223 The response is an `RFileDecoded` JSON containing the table data and definition.
22244. **Modify rows** – Edit the decoded JSON: add, remove, or change rows/cells.
2225 Each row is typically a list of `DecodedData` values matching the table's
2226 fields processed list (retrievable via the `FieldsProcessed` message).
22275. **Save back** – Call `save_packed_file_from_view` with the pack key, the same path,
2228 and the modified `RFileDecoded` JSON as the `data` parameter.
22296. **Save the pack** – Call `save_packfile` (or `save_pack_as` for a new path).
2230
2231Tips:
2232- Use `get_table_definition_from_dependency_pack_file` to see the expected column schema.
2233- Use `get_reference_data_from_definition` to discover valid values for referenced columns.
2234- After saving, you can run `diagnostics_check` to validate the pack.
2235",
2236 )]
2237 }
2238
2239 #[prompt(name = "create_new_mod", description = "Step-by-step guide for creating a new mod PackFile from scratch.")]
2240 pub async fn create_new_mod(&self) -> Vec<PromptMessage> {
2241 vec![PromptMessage::new_text(
2242 PromptMessageRole::User,
2243 "\
2244You are an assistant helping the user create a new Total War mod from scratch.
2245
2246Workflow:
2247
22481. **Set the game** – `set_game_selected` with the target game key and
2249 `rebuild_dependencies: true`.
2250
22512. **Create the pack** – `new_pack` returns a new empty pack and its pack key.
2252
22533. **Set pack type** – `set_pack_file_type` to `\"Mod\"` (the standard type for mods).
2254
22554. **Add DB tables** – For each table you need:
2256 a. Call `new_packed_file` with the pack key, the path (e.g. `\"db/land_units_tables/my_mod\"`),
2257 and the `new_file` JSON set to `\"DB\"` with the table name.
2258 b. Decode, edit, and save as described in the `edit_db_table` workflow.
2259
22605. **Add Loc files** – For localisation:
2261 a. `new_packed_file` with path `\"text/db/my_mod.loc\"` and `new_file` set to `\"Loc\"`.
2262 b. Decode, add key/value rows, and save.
2263
22646. **Add other files** – Use `add_packed_files` to import assets from disk (images, models, etc.).
2265
22667. **Save the pack** – `save_pack_as` to write the final `.pack` file to disk.
2267
2268Optional steps:
2269- `initialize_my_mod_folder` to set up a mod development folder with IDE support.
2270- `optimize_pack_file` to strip unchanged rows that match vanilla data.
2271- `diagnostics_check` to validate everything before release.
2272",
2273 )]
2274 }
2275
2276 #[prompt(name = "search_and_replace", description = "Find and replace values across all files in a pack.")]
2277 pub async fn search_and_replace(&self) -> Vec<PromptMessage> {
2278 vec![PromptMessage::new_text(
2279 PromptMessageRole::User,
2280 "\
2281You are an assistant helping the user search for and replace data across a PackFile.
2282
2283Workflow:
2284
22851. **Open the pack** and **set the game** (see `open_and_inspect_pack` prompt).
2286
22872. **Run a global search** – Call `global_search` with the pack key and a `GlobalSearch`
2288 JSON object. The search object specifies the pattern, whether to use regex, which file
2289 types to include (DB, Loc, Text), and the replacement string.
2290
22913. **Review matches** – The response contains all matches grouped by file.
2292 Present them to the user for review.
2293
22944. **Replace selectively** – Call `global_search_replace_matches` with the same search
2295 object and a `Vec<MatchHolder>` containing only the matches the user approved.
2296
22975. **Or replace all** – If the user confirms a blanket replace, call
2298 `global_search_replace_all` with the search object.
2299
23006. **Save** – `save_packfile` to persist changes.
2301
2302Related tools:
2303- `search_references` – Find all rows that reference a specific value across tables.
2304- `go_to_definition` – Jump to where a referenced key is defined.
2305- `go_to_loc` – Find the loc entry for a given key.
2306",
2307 )]
2308 }
2309
2310 #[prompt(name = "manage_dependencies", description = "Set up and work with game dependencies and vanilla data.")]
2311 pub async fn manage_dependencies(&self) -> Vec<PromptMessage> {
2312 vec![PromptMessage::new_text(
2313 PromptMessageRole::User,
2314 "\
2315You are an assistant helping the user work with dependency data (vanilla game files).
2316
2317Workflow:
2318
23191. **Set the game** – `set_game_selected` with `rebuild_dependencies: true`.
2320
23212. **Check dependency database** – `is_there_a_dependency_database` with `true` to verify
2322 that game data (including Assembly Kit data) is loaded.
2323 If it returns false, call `generate_dependencies_cache` first.
2324
23253. **Browse vanilla tables** – `get_table_list_from_dependency_pack_file` returns all
2326 DB table names from the vanilla game files.
2327
23284. **Read vanilla data** – `get_tables_from_dependencies` with a table name to get
2329 all rows from vanilla for that table.
2330
23315. **Get definitions** – `get_table_definition_from_dependency_pack_file` to get the
2332 schema definition for any table.
2333
23346. **Import from vanilla** – `import_dependencies_to_open_pack_file` to copy specific
2335 files from vanilla into your mod pack.
2336
23377. **Open CA packs** – `load_all_ca_pack_files` opens all vanilla packs as one merged
2338 read-only pack for full browsing.
2339
23408. **Cross-source lookups** – `get_rfiles_from_all_sources` retrieves files by path
2341 from PackFile, GameFiles, and ParentFiles simultaneously.
2342
2343Tips:
2344- Use `get_packed_files_names_starting_with_path_from_all_sources` to discover files
2345 under a given path prefix across all sources.
2346- `set_dependency_pack_files_list` lets you mark other mods as dependencies of your pack.
2347",
2348 )]
2349 }
2350
2351 #[prompt(name = "run_diagnostics", description = "Validate a pack and fix common issues.")]
2352 pub async fn run_diagnostics(&self) -> Vec<PromptMessage> {
2353 vec![PromptMessage::new_text(
2354 PromptMessageRole::User,
2355 "\
2356You are an assistant helping the user validate a Total War mod PackFile.
2357
2358Workflow:
2359
23601. **Open the pack** and **set the game** with `rebuild_dependencies: true`.
2361
23622. **Generate dependencies** – If dependencies have not been generated yet,
2363 call `generate_dependencies` to build the dependency data needed for diagnostics.
2364
23653. **Run full diagnostics** – `diagnostics_check` with an empty `ignored` list
2366 and `check_ak_only_refs: false` (or `true` to include Assembly Kit references).
2367 The response contains all warnings and errors grouped by category.
2368
23694. **Review results** – Present the diagnostic results to the user, grouped by severity.
2370 Common issues include:
2371 - Invalid references (a column references a key that does not exist)
2372 - Duplicate keys
2373 - Empty loc entries
2374 - Outdated table versions
2375
23765. **Fix issues** – For each issue:
2377 - Decode the affected file with `decode_packed_file`.
2378 - Apply the fix (correct a reference, remove a duplicate row, etc.).
2379 - Save with `save_packed_file_from_view`.
2380
23816. **Ignore false positives** – Use `add_line_to_pack_ignored_diagnostics` to suppress
2382 specific diagnostic lines that are intentional.
2383
23847. **Re-check** – After fixes, call `diagnostics_check` again to confirm all issues
2385 are resolved.
2386
23878. **Optimize** – Optionally run `optimize_pack_file` to remove rows that are identical
2388 to vanilla, reducing pack size.
2389",
2390 )]
2391 }
2392
2393 #[prompt(name = "schema_operations", description = "Work with table schemas: inspect, update, and patch definitions.")]
2394 pub async fn schema_operations(&self) -> Vec<PromptMessage> {
2395 vec![PromptMessage::new_text(
2396 PromptMessageRole::User,
2397 "\
2398You are an assistant helping the user manage RPFM table schemas.
2399
2400Workflow:
2401
24021. **Check schema status** – `is_schema_loaded` to verify a schema is loaded.
2403 If not, call `update_schemas` to download the latest from the repository.
2404
24052. **Get the full schema** – `get_schema` returns the entire schema object.
2406
24073. **Inspect a table definition** – `definitions_by_table_name` with a table name
2408 returns all known versions. Use `definition_by_table_name_and_version` for a
2409 specific version.
2410
24114. **See processed fields** – `fields_processed` takes a Definition JSON and returns
2412 fields with bitwise expansion and enum conversions applied (useful for display).
2413
24145. **Find referencing columns** – `referencing_columns_for_definition` shows which
2415 other tables reference a given table's columns.
2416
24176. **Patch a definition** – To customise column metadata (descriptions, references,
2418 default values) without modifying the upstream schema:
2419 a. Build a `HashMap<String, DefinitionPatch>` with your changes.
2420 b. Call `save_local_schema_patch` to persist it locally.
2421 c. Use `remove_local_schema_patches_for_table` or
2422 `remove_local_schema_patches_for_table_and_field` to undo patches.
2423
24247. **Import patches** – `import_schema_patch` applies a patch from another source.
2425
24268. **Update from Assembly Kit** – `update_current_schema_from_asskit` merges
2427 definition data from the game's Assembly Kit into the loaded schema.
2428
24299. **Save the schema** – `save_schema` writes the current in-memory schema to disk.
2430",
2431 )]
2432 }
2433
2434 #[prompt(name = "file_operations", description = "Add, remove, rename, extract, and move files within packs.")]
2435 pub async fn file_operations(&self) -> Vec<PromptMessage> {
2436 vec![PromptMessage::new_text(
2437 PromptMessageRole::User,
2438 "\
2439You are an assistant helping the user manage files inside a Total War PackFile.
2440
2441Common operations:
2442
2443**Add files from disk:**
2444- `add_packed_files` – Import files from the filesystem into the pack. Provide source
2445 filesystem paths and destination `ContainerPath` entries as JSON.
2446
2447**Add files from another pack:**
2448- `add_packed_files_from_pack_file` – Copy files between two open packs.
2449
2450**Create new files:**
2451- `new_packed_file` – Create a blank DB table, Loc file, or other file type inside the pack.
2452
2453**Delete files:**
2454- `delete_packed_files` – Remove files by their `ContainerPath` list.
2455
2456**Rename / move files:**
2457- `rename_packed_files` – Pass a list of `(old_path, new_path)` tuples.
2458
2459**Copy / Cut / Paste / Duplicate:**
2460- `copy_packed_files` – Copy files to the internal clipboard for later pasting.
2461- `cut_packed_files` – Cut files to the internal clipboard (removed from source on paste).
2462- `paste_packed_files` – Paste clipboard contents into a pack at the given folder path.
2463- `duplicate_packed_files` – Clone files in-place with a numeric suffix.
2464
2465**Extract to disk:**
2466- `extract_packed_files` – Export files from the pack to a folder on disk.
2467 Set `export_as_tsv: true` to export tables as TSV files.
2468
2469**AnimPack operations:**
2470- `add_packed_files_from_pack_file_to_animpack` – Add files to an AnimPack.
2471- `add_packed_files_from_animpack` – Extract files from an AnimPack.
2472- `delete_from_animpack` – Remove files from an AnimPack.
2473
2474**File info:**
2475- `get_packed_files_info` / `get_rfile_info` – Get metadata about files.
2476- `folder_exists` / `packed_file_exists` – Check if a path exists.
2477- `get_packed_file_raw_data` – Get the raw binary content of a file.
2478
2479**Merge tables:**
2480- `merge_files` – Combine multiple compatible tables into one.
2481
2482**External editing:**
2483- `open_packed_file_in_external_program` – Open a file in the system's default editor.
2484- `save_packed_file_from_external_view` – Re-import after external editing.
2485
2486Always call `save_packfile` or `save_pack_as` when done to persist changes.
2487",
2488 )]
2489 }
2490
2491 #[prompt(name = "troubleshooting", description = "Diagnose and fix common issues with RPFM and PackFiles.")]
2492 pub async fn troubleshooting(&self) -> Vec<PromptMessage> {
2493 vec![PromptMessage::new_text(
2494 PromptMessageRole::User,
2495 "\
2496You are an assistant helping the user troubleshoot common RPFM and PackFile issues.
2497
2498## Common Issues and Solutions
2499
2500### 1. Schema not loaded
2501**Symptom**: Files fail to decode, or `decode_packed_file` returns raw data.
2502**Solution**:
2503- Call `is_schema_loaded()` – if false, call `update_schemas()`.
2504- Make sure `set_game_selected` was called with `rebuild_dependencies: true`.
2505
2506### 2. Dependencies not available
2507**Symptom**: References show as invalid, diagnostics report missing keys.
2508**Solution**:
2509- Call `is_there_a_dependency_database(true)` – if false, call `generate_dependencies_cache()`.
2510- Ensure the game path is configured correctly in settings.
2511
2512### 3. Pack won't save
2513**Symptom**: `save_packfile` returns an error.
2514**Solution**:
2515- Check if the file is read-only or locked by another process.
2516- Try `save_pack_as` to a different path.
2517- As a last resort, use `clean_and_save_pack_as` to recover from corruption.
2518
2519### 4. Table version mismatch
2520**Symptom**: Table data looks wrong or has missing columns after a game update.
2521**Solution**:
2522- Call `update_schemas()` to get the latest table definitions.
2523- Use `update_table` to migrate the table to the current version.
2524- Check `get_table_definition_from_dependency_pack_file` for the expected schema.
2525
2526### 5. Wrong game selected
2527**Symptom**: Tables decode with wrong columns or fail to decode, dependencies are for a different game.
2528**Solution**:
2529- Call `get_game_selected()` to verify the current game.
2530- Call `set_game_selected` with the correct game key and `rebuild_dependencies: true`.
2531
2532### 6. Diagnostics show many reference errors
2533**Symptom**: `diagnostics_check` reports hundreds of invalid references.
2534**Solution**:
2535- Ensure dependencies are loaded (`is_there_a_dependency_database(true)`).
2536- Check if the pack depends on other mods via `get_dependency_pack_files_list`.
2537- Some references are Assembly Kit only; re-run with `check_ak_only_refs: true`.
2538- Use `add_line_to_pack_ignored_diagnostics` for intentional deviations.
2539
2540### Diagnostic Tools
2541- `diagnostics_check` – Full pack validation.
2542- `get_game_selected` – Verify game context.
2543- `is_schema_loaded` – Check schema status.
2544- `is_there_a_dependency_database` – Check dependency database status.
2545- `list_open_packs` – Verify which packs are open.
2546- `config_path` / `schemas_path` – Verify RPFM paths.
2547",
2548 )]
2549 }
2550
2551 #[prompt(name = "tsv_workflow", description = "Import and export tables as TSV files for batch editing in spreadsheets.")]
2552 pub async fn tsv_workflow(&self) -> Vec<PromptMessage> {
2553 vec![PromptMessage::new_text(
2554 PromptMessageRole::User,
2555 "\
2556You are an assistant helping the user work with TSV (Tab-Separated Values) files for batch editing \
2557Total War mod data in spreadsheets.
2558
2559## Export Workflow (Pack → TSV → Spreadsheet)
2560
25611. **Open the pack** and **set the game** with `rebuild_dependencies: true`.
2562
25632. **Export a single table as TSV**:
2564 Call `export_tsv` with:
2565 - `pack_key`: the pack key
2566 - `tsv_path`: destination path on disk (e.g. `/home/user/my_table.tsv`)
2567 - `table_path`: the internal path (e.g. `db/land_units_tables/my_mod`)
2568
25693. **Export all tables as TSV**:
2570 Call `extract_packed_files` with `export_as_tsv: true`.
2571 This exports all tables in the pack as TSV files to the destination folder.
2572
25734. **Edit in a spreadsheet**: Open the TSV file in LibreOffice Calc, Excel, or Google Sheets.
2574 - Keep the header rows intact (they contain schema metadata).
2575 - Tab-separated values — do not change the delimiter.
2576
2577## Import Workflow (Spreadsheet → TSV → Pack)
2578
25791. **Save the spreadsheet as TSV** (tab-delimited, UTF-8 encoding).
2580
25812. **Import the TSV back**:
2582 Call `import_tsv` with:
2583 - `pack_key`: the target pack key
2584 - `tsv_path`: path to the TSV file on disk
2585 - `table_path`: the internal path where the table should go
2586
25873. **Verify**: Call `decode_packed_file` to confirm the data imported correctly.
2588
25894. **Save the pack**: Call `save_packfile` to persist changes.
2590
2591## Tips
2592- TSV files include metadata headers that RPFM uses for schema matching.
2593 Do not delete or modify these header rows.
2594- Use `get_table_definition_from_dependency_pack_file` to understand column types
2595 before editing.
2596- After import, run `diagnostics_check` to validate references.
2597",
2598 )]
2599 }
2600
2601 #[prompt(name = "translation_workflow", description = "Work with localisation and translation data in PackFiles.")]
2602 pub async fn translation_workflow(&self) -> Vec<PromptMessage> {
2603 vec![PromptMessage::new_text(
2604 PromptMessageRole::User,
2605 "\
2606You are an assistant helping the user work with localisation (translation) data in Total War mods.
2607
2608## Understanding Loc Files
2609
2610Loc files contain key-value pairs for in-game text. Each entry has:
2611- A **key** (unique identifier referenced by DB tables)
2612- A **value** (the displayed text in the game)
2613
2614## Viewing Existing Translations
2615
26161. **Open the pack** and **set the game**.
2617
26182. **Decode a loc file**:
2619 Call `decode_packed_file` with the loc file path (e.g. `text/db/my_mod.loc`)
2620 and `source: \"PackFile\"`.
2621
26223. **Get translation overview**:
2623 Call `get_pack_translation` with the pack key and a language code
2624 (e.g. `\"en\"`, `\"fr\"`, `\"de\"`, `\"es\"`, `\"it\"`, `\"zh\"`, `\"ru\"`, etc.).
2625
2626## Creating New Translations
2627
26281. **Create a new loc file**:
2629 Call `new_packed_file` with path `\"text/db/my_mod.loc\"` and
2630 `new_file = {\"Loc\": \"my_mod\"}`.
2631
26322. **Decode it**: `decode_packed_file` to get the empty structure.
2633
26343. **Add entries**: Modify the decoded JSON to add key-value rows.
2635 Each row is typically `[\"key_string\", \"Displayed text in game\"]`.
2636
26374. **Save back**: `save_packed_file_from_view` with the modified data.
2638
2639## Generating Missing Loc Data
2640
2641Call `generate_missing_loc_data` with the pack key to auto-generate
2642loc entries for DB fields that reference loc keys but don't have entries yet.
2643
2644## Finding Loc Keys
2645
2646- Use `go_to_loc` with a loc key to find its source loc file.
2647- Use `get_source_data_from_loc_key` to find where a loc key is referenced.
2648- Use `global_search` with `search_on.loc: true` to search across all loc files.
2649
2650## Tips
2651- Loc keys follow naming conventions like `<table>_<loc_column_name>_<keys_concatenated>`.
2652- Use `search_references` to find all DB columns that reference a specific loc key.
2653- After adding translations, run `diagnostics_check` to verify all references.
2654",
2655 )]
2656 }
2657}