-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
The MCP library tries to do type introspection at runtime, but is choking on the union types in the code.
The issue was caused by type annotations in the MCP tool function parameters. The MCP library's issubclass() check was failing because it couldn't handle certain type annotations like typing.Any,
typing.Optional[str], union types, and return type annotations.
The fix involved:
- Removing all parameter type annotations from @mcp.tool() decorated functions
- Removing **kwargs type annotations
- Removing return type annotations
- Keeping default parameter values intact
Original error
2025-08-07 09:45:21,894 - src.main - INFO - Registering MCP tools...
Traceback (most recent call last):
File "/Users/brobert/Documents/code/chrome-devtools-mcp/server.py", line 33, in <module>
from src import main
File "/Users/brobert/Documents/code/chrome-devtools-mcp/src/__init__.py", line 6, in <module>
from . import main
File "/Users/brobert/Documents/code/chrome-devtools-mcp/src/main.py", line 75, in <module>
register_all_tools()
~~~~~~~~~~~~~~~~~~^^
File "/Users/brobert/Documents/code/chrome-devtools-mcp/src/main.py", line 62, in register_all_tools
register_chrome_tools(mcp)
~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/Users/brobert/Documents/code/chrome-devtools-mcp/src/tools/chrome_management.py", line 171, in register_chrome_tools
@mcp.tool()
~~~~~~~~^^
File "/opt/homebrew/lib/python3.13/site-packages/mcp/server/fastmcp/server.py", line 421, in decorator
self.add_tool(
~~~~~~~~~~~~~^
fn,
^^^
...<4 lines>...
structured_output=structured_output,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/opt/homebrew/lib/python3.13/site-packages/mcp/server/fastmcp/server.py", line 366, in add_tool
self._tool_manager.add_tool(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
fn,
^^^
...<4 lines>...
structured_output=structured_output,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/opt/homebrew/lib/python3.13/site-packages/mcp/server/fastmcp/tools/tool_manager.py", line 55, in add_tool
tool = Tool.from_function(
fn,
...<4 lines>...
structured_output=structured_output,
)
File "/opt/homebrew/lib/python3.13/site-packages/mcp/server/fastmcp/tools/base.py", line 67, in from_function
if issubclass(param.annotation, Context):
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen abc>", line 123, in __subclasscheck__
TypeError: issubclass() arg 1 must be a class
Repair
See provided diff. I would hope that there is a more elegant way to fix this than what Claude did, but this at least got the mcp server running for me and I'm providing it just in case it helps.
Metadata
Metadata
Assignees
Labels
No labels