Commit 5be0dbc
* fix(api): apply query and header mappings on tool invocation (#1405)
When a tool has query_mapping or header_mapping configured, apply those
mappings during REST tool invocation so that argument fields are correctly
translated into query parameters and HTTP headers.
Closes #1405
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix(test): add unit tests for apply_mapping_into_target and fix regressions
- Add 9 unit tests for the apply_mapping_into_target utility covering
key renaming, target merging, overwrite semantics, None/empty mapping
handling, unmapped key exclusion, and input immutability
- Fix 2 TestRustMcpExecutionPlan tests broken by missing query_mapping
and header_mapping attributes on mock tool SimpleNamespace objects
- Add assertions verifying query_mapping and header_mapping are included
in _build_tool_cache_payload output
- Remove spurious query_mapping/header_mapping from gateway mock (gateways
do not have these fields)
- Apply Black formatting to apply_mapping_into_target
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix(api): harden query/header mapping with security validation, type guards, and tests
Tighten Dict[str, Any] to Dict[str, str] for query_mapping and header_mapping
in schemas, DB model, and Pydantic validation. Add schema-level size constraints
(max 50 entries, 128 char keys/values) on ToolCreate and ToolUpdate.
At invocation time, validate header mapping targets against sensitive header
patterns (Authorization, Proxy-Authorization, X-API-Key, etc.) and RFC 7230
header name syntax to prevent auth header overwrite and CRLF injection. Add
isinstance guards with dict-content validation matching the tool_oauth_config
pattern, and wrap mapping call sites in try/except for clear error messages
when mappings are corrupt.
Includes debug-level logging for unmapped keys, improved docstrings and inline
comments, mock_tool fixture defaults, and test coverage for GET method,
empty-dict mappings, URL-template param availability in headers, sensitive
header rejection, CRLF injection rejection, and content validation.
Closes #1405
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jonathan Springer <jps@s390x.com>
---------
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Signed-off-by: Jonathan Springer <jps@s390x.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Jonathan Springer <jps@s390x.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2b2b1a1 commit 5be0dbc
5 files changed
Lines changed: 685 additions & 33 deletions
File tree
- mcpgateway
- services
- tests/unit/mcpgateway/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | | - | |
| 411 | + | |
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | | - | |
| 419 | + | |
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
| |||
5962 | 5962 | | |
5963 | 5963 | | |
5964 | 5964 | | |
5965 | | - | |
| 5965 | + | |
5966 | 5966 | | |
5967 | 5967 | | |
5968 | 5968 | | |
5969 | 5969 | | |
5970 | 5970 | | |
5971 | 5971 | | |
5972 | 5972 | | |
5973 | | - | |
| 5973 | + | |
5974 | 5974 | | |
5975 | 5975 | | |
5976 | 5976 | | |
5977 | 5977 | | |
5978 | 5978 | | |
5979 | 5979 | | |
5980 | 5980 | | |
5981 | | - | |
| 5981 | + | |
5982 | 5982 | | |
5983 | 5983 | | |
5984 | 5984 | | |
5985 | 5985 | | |
5986 | 5986 | | |
5987 | 5987 | | |
5988 | 5988 | | |
5989 | | - | |
| 5989 | + | |
5990 | 5990 | | |
5991 | 5991 | | |
5992 | 5992 | | |
5993 | 5993 | | |
5994 | 5994 | | |
5995 | 5995 | | |
5996 | 5996 | | |
5997 | | - | |
| 5997 | + | |
5998 | 5998 | | |
5999 | 5999 | | |
6000 | 6000 | | |
6001 | 6001 | | |
6002 | 6002 | | |
6003 | 6003 | | |
6004 | 6004 | | |
6005 | | - | |
| 6005 | + | |
6006 | 6006 | | |
6007 | 6007 | | |
6008 | 6008 | | |
| |||
9682 | 9682 | | |
9683 | 9683 | | |
9684 | 9684 | | |
9685 | | - | |
| 9685 | + | |
9686 | 9686 | | |
9687 | 9687 | | |
9688 | 9688 | | |
9689 | 9689 | | |
9690 | 9690 | | |
9691 | 9691 | | |
9692 | 9692 | | |
9693 | | - | |
| 9693 | + | |
9694 | 9694 | | |
9695 | 9695 | | |
9696 | 9696 | | |
9697 | 9697 | | |
9698 | 9698 | | |
9699 | 9699 | | |
9700 | 9700 | | |
9701 | | - | |
| 9701 | + | |
9702 | 9702 | | |
9703 | 9703 | | |
9704 | 9704 | | |
9705 | 9705 | | |
9706 | 9706 | | |
9707 | 9707 | | |
9708 | 9708 | | |
9709 | | - | |
| 9709 | + | |
9710 | 9710 | | |
9711 | 9711 | | |
9712 | 9712 | | |
9713 | 9713 | | |
9714 | 9714 | | |
9715 | 9715 | | |
9716 | 9716 | | |
9717 | | - | |
| 9717 | + | |
9718 | 9718 | | |
9719 | 9719 | | |
9720 | 9720 | | |
9721 | 9721 | | |
9722 | 9722 | | |
9723 | 9723 | | |
9724 | 9724 | | |
9725 | | - | |
| 9725 | + | |
9726 | 9726 | | |
9727 | 9727 | | |
9728 | 9728 | | |
9729 | 9729 | | |
9730 | 9730 | | |
9731 | 9731 | | |
9732 | 9732 | | |
9733 | | - | |
| 9733 | + | |
9734 | 9734 | | |
9735 | 9735 | | |
9736 | 9736 | | |
9737 | 9737 | | |
9738 | 9738 | | |
9739 | 9739 | | |
9740 | 9740 | | |
9741 | | - | |
| 9741 | + | |
9742 | 9742 | | |
9743 | 9743 | | |
9744 | 9744 | | |
9745 | 9745 | | |
9746 | 9746 | | |
9747 | 9747 | | |
9748 | 9748 | | |
9749 | | - | |
| 9749 | + | |
9750 | 9750 | | |
9751 | 9751 | | |
9752 | 9752 | | |
9753 | 9753 | | |
9754 | 9754 | | |
9755 | 9755 | | |
9756 | 9756 | | |
9757 | | - | |
| 9757 | + | |
9758 | 9758 | | |
9759 | 9759 | | |
9760 | 9760 | | |
9761 | 9761 | | |
9762 | 9762 | | |
9763 | 9763 | | |
9764 | 9764 | | |
9765 | | - | |
| 9765 | + | |
9766 | 9766 | | |
9767 | 9767 | | |
9768 | 9768 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3231 | 3231 | | |
3232 | 3232 | | |
3233 | 3233 | | |
3234 | | - | |
3235 | | - | |
| 3234 | + | |
| 3235 | + | |
3236 | 3236 | | |
3237 | 3237 | | |
3238 | 3238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
61 | 123 | | |
62 | 124 | | |
63 | 125 | | |
| |||
415 | 477 | | |
416 | 478 | | |
417 | 479 | | |
418 | | - | |
419 | | - | |
| 480 | + | |
| 481 | + | |
420 | 482 | | |
421 | 483 | | |
422 | 484 | | |
| |||
944 | 1006 | | |
945 | 1007 | | |
946 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
947 | 1021 | | |
948 | 1022 | | |
949 | 1023 | | |
| |||
984 | 1058 | | |
985 | 1059 | | |
986 | 1060 | | |
987 | | - | |
988 | | - | |
| 1061 | + | |
| 1062 | + | |
989 | 1063 | | |
990 | 1064 | | |
991 | 1065 | | |
| |||
1384 | 1458 | | |
1385 | 1459 | | |
1386 | 1460 | | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
1387 | 1473 | | |
1388 | 1474 | | |
1389 | 1475 | | |
| |||
1451 | 1537 | | |
1452 | 1538 | | |
1453 | 1539 | | |
1454 | | - | |
1455 | | - | |
| 1540 | + | |
| 1541 | + | |
1456 | 1542 | | |
1457 | 1543 | | |
1458 | 1544 | | |
| |||
0 commit comments