Title: fix: reject trailing newline in tool-name validation by Otis0408 · Pull Request #3076 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: reject trailing newline in tool-name validation by Otis0408 · Pull Request #3076 · modelcontextprotocol/python-sdk
X Title: fix: reject trailing newline in tool-name validation by Otis0408 · Pull Request #3076 · modelcontextprotocol/python-sdk
Description: Closes #3084 Summary TOOL_NAME_REGEX in src/mcp/shared/tool_name_validation.py is end-anchored with $: TOOL_NAME_REGEX = re.compile(r"^[A-Za-z0-9._-]{1,128}$") In Python's default (non-MULTILINE) mode, $ matches at end-of-string or immediately before a single trailing \n. So a tool name ending in exactly one newline passes validation: >>> validate_tool_name("evil_tool\n").is_valid True # expected: False (newline is not an allowed SEP-986 character) >>> validate_and_warn_tool_name("evil_tool\n") True # no warning logged The length guard uses len() (which counts the \n), so "a" * 127 + "\n" (length 128) also slips past both the length and the character check. Embedded and non-\n trailing control chars are already rejected correctly — only the single-trailing-newline case leaks. Fix Anchor the end with \Z (strict end-of-string) instead of $. No valid name is affected — re.match(r"^[A-Za-z0-9._-]{1,128}\Z", "abc") still matches; only "abc\n" now correctly fails. Tests Adds test_validate_tool_name_rejects_trailing_newline (parametrized over a trailing-newline name and a 128-char name whose last char is \n). Verified it fails on main (is_valid=True) and passes with the fix; the file's existing 29 tests are unchanged (no valid-name fixture ends in a newline).
Open Graph Description: Closes #3084 Summary TOOL_NAME_REGEX in src/mcp/shared/tool_name_validation.py is end-anchored with $: TOOL_NAME_REGEX = re.compile(r"^[A-Za-z0-9._-]{1,128}$") In Python's default (no...
X Description: Closes #3084 Summary TOOL_NAME_REGEX in src/mcp/shared/tool_name_validation.py is end-anchored with $: TOOL_NAME_REGEX = re.compile(r"^[A-Za-z0-9._-]{1,128}$") In Python's...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3076
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d4e47aa5-7991-d84d-c0f9-db3ece75474a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C57A:390ECE:61C95EF:89A1520:6A57416B |
| html-safe-nonce | 61581b0551f15d0727601d3cdcd108d00d64ee7c7e4a920ac307f2bb8b10dada |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTdBOjM5MEVDRTo2MUM5NUVGOjg5QTE1MjA6NkE1NzQxNkIiLCJ2aXNpdG9yX2lkIjoiNjc2MDA1OTA3ODYyOTA4MTQ1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c4d8a76593644badab45954c7d441ce2283a776baab8e4cc2250891b7d95d7ad |
| hovercard-subject-tag | pull_request:4013943323 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3076/files |
| twitter:image | https://avatars.githubusercontent.com/u/75174115?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/75174115?s=400&v=4 |
| og:image:alt | Closes #3084 Summary TOOL_NAME_REGEX in src/mcp/shared/tool_name_validation.py is end-anchored with $: TOOL_NAME_REGEX = re.compile(r"^[A-Za-z0-9._-]{1,128}$") In Python's default (no... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4e7a7296a3830877cf21a6ad2a972c9e618a48915e03966cf0c53eb08e5aad98 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2576d1f0198cf1588faf2edf27f1ed120903be10 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width