0
0
Fork 0
Codesys-MCP-SP21-plus/src/scripts
Karstein Phobic Nyvold Kvistad fc49e7ff8b fix(add_library): dedup pre-check + default to add_placeholder, opt-in direct/force
Empirical failure: add_library('Standard') on a project that already had Standard, * (System) silently created a SECOND direct Standard reference, pulling in unresolved transitive deps (e.g. yellow-warning IoStandard 3.1.3.1).
Root cause: script always called add_library() without checking lm.references first; never called add_placeholder() so the result was a direct (non-* (System)) reference.
Fix: (1) walk lm.references for an existing entry by bare name and no-op with a confirmation message unless force=true; (2) default to add_placeholder() so transitive deps resolve at compile (matches the modern '<Name>, * (System)' convention); (3) keep add_library() reachable via direct=true; (4) on miss, dump dir(lm) so unknown SPs surface the actual API.
Docs: https://content.helpme-codesys.com/en/ScriptingEngine/ScriptLibManObject.html

Mildly breaking for callers: previous behaviour was always direct
add_library(); pass direct=true to restore. The dedup default also flips
'add second copy' to 'no-op' -- pass force=true to restore.

Test updated: tests/integration/e2e.test.ts now passes USE_DIRECT='0' and
FORCE_DUP='0' alongside LIBRARY_NAME, asserts add_placeholder + dedup
strings appear in the rendered script.

### Manual smoke test
1. mcp__codesys__add_library libraryName=Standard against a project that
   already has Standard listed: expect SCRIPT_SUCCESS with body 'Library
   Already Present: Standard' and NO second entry in the Library Manager.
2. mcp__codesys__add_library libraryName=Util on a project without Util:
   expect a new entry rendered as 'Util, * (System)' (placeholder, not
   direct).
3. mcp__codesys__add_library libraryName=Standard direct=true: expect a
   direct (non-* (System)) reference even on dedup hit if also force=true.
4. mcp__codesys__list_project_libraries should reflect each result.
2026-04-28 20:54:34 +02:00
..
add_library.py fix(add_library): dedup pre-check + default to add_placeholder, opt-in direct/force 2026-04-28 20:54:34 +02:00
bump_project_version.py fix(read_running_version_online): document the real root cause + fix 2026-04-26 20:13:25 +02:00
check_status.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
compile_project.py fix(compile): deep-walk message structures with _coerce_for_json before json.dumps 2026-04-28 20:50:15 +02:00
connect_to_device.py fix: 4 broken-tool fixes (compile json long, connect_to_device LoginMode, 2026-04-26 16:53:25 +02:00
create_dut.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
create_folder.py fix(create_folder): dump dir(parent) on total-miss to diagnose unknown SPs 2026-04-28 20:51:32 +02:00
create_gvl.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
create_method.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
create_pou.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
create_project.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
create_property.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
delete_object.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
disconnect_from_device.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
download_to_device.py fix(download_to_device): port login() probe + loginWaitSeconds from connect 2026-04-25 18:40:26 +02:00
ensure_online_connection.py fix(online tools): auto-login + non-CONSTANT version GVL 2026-04-26 19:54:13 +02:00
ensure_project_open.py fix: 4 broken-tool fixes (compile json long, connect_to_device LoginMode, 2026-04-26 16:53:25 +02:00
find_object_by_path.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
get_all_pou_code.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
get_application_state.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
get_compile_messages.py fix(compile): deep-walk message structures with _coerce_for_json before json.dumps 2026-04-28 20:50:15 +02:00
get_pou_code.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
get_project_structure.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
list_project_libraries.py feat(list_project_libraries): capture project compiler version 2026-04-26 19:18:31 +02:00
mirror_export.py fix(mirror): per-project mirror dir name when multiple .project files share a parent 2026-04-27 22:22:09 +02:00
open_project.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
read_running_version_online.py fix(read_running_version_online): document the real root cause + fix 2026-04-26 20:13:25 +02:00
read_variable.py fix(online tools): auto-login + non-CONSTANT version GVL 2026-04-26 19:54:13 +02:00
rename_object.py Add 17 new MCP tools for v0.4.0: compiler diagnostics, project authoring, runtime monitoring, library management 2026-02-08 21:05:12 +10:00
save_project.py Initial release: MCP server for CODESYS with persistent UI instance 2026-02-08 18:59:16 +10:00
set_pou_code.py fix(set_pou_code): omitted declaration/impl no longer wipes the POU 2026-04-26 18:41:48 +02:00
start_stop_application.py fix(online tools): auto-login + non-CONSTANT version GVL 2026-04-26 19:54:13 +02:00
watcher.py fix(watcher): use ASCII-only comments/log strings (IronPython 2.7 syntax error) 2026-04-25 15:10:21 +02:00
write_variable.py fix(online tools): auto-login + non-CONSTANT version GVL 2026-04-26 19:54:13 +02:00