Title: Decorator type signatures lose parameter types (use ParamSpec) · Issue #1822 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Decorator type signatures lose parameter types (use ParamSpec) · Issue #1822 · modelcontextprotocol/python-sdk
X Title: Decorator type signatures lose parameter types (use ParamSpec) · Issue #1822 · modelcontextprotocol/python-sdk
Description: Issue: Decorator type signatures lose parameter types Summary The MCP server decorators (@server.call_tool(), @server.list_tools(), etc.) use Callable[..., Awaitable[...]] which discards parameter type information, preventing static type...
Open Graph Description: Issue: Decorator type signatures lose parameter types Summary The MCP server decorators (@server.call_tool(), @server.list_tools(), etc.) use Callable[..., Awaitable[...]] which discards parameter ...
X Description: Issue: Decorator type signatures lose parameter types Summary The MCP server decorators (@server.call_tool(), @server.list_tools(), etc.) use Callable[..., Awaitable[...]] which discards parameter ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1822
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Decorator type signatures lose parameter types (use ParamSpec)","articleBody":"# Issue: Decorator type signatures lose parameter types\n\n## Summary\n\nThe MCP server decorators (`@server.call_tool()`, `@server.list_tools()`, etc.) use `Callable[..., Awaitable[...]]` which discards parameter type information, preventing static type checkers from validating decorated functions.\n\n## Current Behavior\n\n```python\n# In mcp/server/lowlevel/server.py\ndef call_tool(self, *, validate_input: bool = True):\n def decorator(\n func: Callable[\n ..., # \u003c-- Ellipsis loses parameter types!\n Awaitable[UnstructuredContent | StructuredContent | ...],\n ],\n ):\n # ...\n```\n\nWhen decorating a function:\n```python\n@server.call_tool() # type: ignore # \u003c-- Required!\nasync def call_tool(name: str, arguments: dict[str, object]) -\u003e list[TextContent]:\n ...\n```\n\nMypy cannot verify:\n- Parameter names/types are correct\n- Arguments are passed correctly to decorated function\n- Return type matches decorator constraints\n\n## Expected Behavior\n\nDecorators should preserve parameter types using `ParamSpec`:\n\n```python\nfrom typing import ParamSpec, TypeVar, Callable, Awaitable\n\nP = ParamSpec('P')\nR = TypeVar('R')\n\ndef call_tool(self, *, validate_input: bool = True):\n def decorator(\n func: Callable[P, Awaitable[R]]\n ) -\u003e Callable[P, Awaitable[R]]:\n # ... wrapper implementation\n return func # Type signature preserved\n```\n\nThis would:\n- ✅ Preserve parameter types through decoration\n- ✅ Enable static type checking\n- ✅ Eliminate need for `# type: ignore`\n- ✅ Improve IDE autocomplete/hints\n\n## Environment\n\n- **mcp version**: 1.24.0\n- **Python version**: 3.14 (but affects 3.10+)\n- **Type checker**: mypy (strict mode)\n\n## Impact\n\nThe package includes `py.typed` marker claiming type support, but decorators break type checking. Projects using strict mypy must either:\n1. Disable type checking for entire MCP server modules\n2. Add `# type: ignore` to every decorated function\n3. Create local type stubs to work around the issue\n\n## Workaround\n\nCurrently using broad mypy overrides:\n```toml\n[[tool.mypy.overrides]]\nmodule = \"myproject.mcp_server\"\ndisable_error_code = [\"misc\", \"no-untyped-call\", \"explicit-any\"]\n```\n\nThis defeats the purpose of having `py.typed`.\n\n## Related\n\n- Python typing docs: https://docs.python.org/3/library/typing.html#typing.ParamSpec\n- Similar issue in other libraries: https://github.com/python/mypy/issues/1927","author":{"url":"https://github.com/Morriz","@type":"Person","name":"Morriz"},"datePublished":"2026-01-01T21:03:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1822/python-sdk/issues/1822"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:623e1759-a94b-6d45-208a-63a733ead0fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 961A:251DF3:22500CC:2D08DAC:6A5CAD75 |
| html-safe-nonce | 4f76161d5936aae2d869bd201a21b1ba26d7d329ed6642fe137988ade4e018fc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjFBOjI1MURGMzoyMjUwMENDOjJEMDhEQUM6NkE1Q0FENzUiLCJ2aXNpdG9yX2lkIjoiNzY1NTE5MjE0NTAwNDYzNzU1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ed970aefadf4716e92d78f265a74285a8314a8f9c83258a2fbd19a38d44ff0a9 |
| hovercard-subject-tag | issue:3775194772 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1822/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5e501c12904e5f375a5bddc83f8a2a2290fef9205bc8e37438447c7d604dfc8/modelcontextprotocol/python-sdk/issues/1822 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5e501c12904e5f375a5bddc83f8a2a2290fef9205bc8e37438447c7d604dfc8/modelcontextprotocol/python-sdk/issues/1822 |
| og:image:alt | Issue: Decorator type signatures lose parameter types Summary The MCP server decorators (@server.call_tool(), @server.list_tools(), etc.) use Callable[..., Awaitable[...]] which discards parameter ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Morriz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width