Skip to content

TypeError in Generic Class Definition #4

@jbrandtmse

Description

@jbrandtmse

Hello,

I'm trying to get this MCP server to work with Cline... Here is the bug report it generated. Any suggestions as to what else I should try?

Bug Report: TypeError in Generic Class Definition - mcp-server-iris v0.2.2

Summary

mcp-server-iris v0.2.2 fails to start with a TypeError related to typing.Generic class definition on Python 3.12, preventing the MCP server from functioning.

Environment Details

  • Package: mcp-server-iris v0.2.2
  • Python Version: 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)]
  • Operating System: Windows 11
  • Pydantic Version: 2.10.6 (user environment), 2.11.7 (fresh isolated environments)
  • Installation Methods Tested: pip, pipx, uv tool

Steps to Reproduce

Method 1: Direct module execution

python -m mcp_server_iris --help

Method 2: Executable execution

mcp-server-iris.exe --help

Method 3: UV tool execution

uv tool run mcp-server-iris --help

Expected Behavior

The MCP server should start successfully and display help information or accept connections.

Actual Behavior

All execution methods fail with the same TypeError:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "...\mcp-server-iris.exe\__main__.py", line 4, in <module>
  File "...\mcp_server_iris\__init__.py", line 1, in <module>
    from .server import main as main # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\mcp_server_iris\server.py", line 7, in <module>
    from mcp_server_iris.mcpserver import MCPServer, Context, logger
  File "...\mcp_server_iris\mcpserver.py", line 23, in <module>
    class MCPServerContext(Context, Generic[ServerSessionT, LifespanContextT]):
  File "...\pydantic\_internal\_model_construction.py", line 198, in __new__
    raise TypeError(error_message)
TypeError: All parameters must be present on typing.Generic; you should inherit from typing.Generic[~ServerSessionT, ~LifespanContextT, ~RequestT].

Root Cause Analysis

Location of Issue

File: mcp_server_iris/mcpserver.py
Line: 23
Class: MCPServerContext

Problem Description

The class definition:

class MCPServerContext(Context, Generic[ServerSessionT, LifespanContextT]):

Is missing the required RequestT parameter that pydantic expects based on the error message:

you should inherit from typing.Generic[~ServerSessionT, ~LifespanContextT, ~RequestT]

Pydantic Validation

Pydantic's model construction is enforcing that all type parameters defined elsewhere in the class hierarchy must be present in the Generic declaration.

Comprehensive Testing Performed

Installation Method Testing

  1. pip install mcp-server-iris ✅ Installed successfully, same error
  2. pipx install mcp-server-iris ✅ Installed in isolated environment, same error
  3. uv tool install mcp-server-iris ✅ Installed with fresh dependencies, same error

Environment Testing

  • User Python Environment: pydantic 2.10.6 - Same error
  • Isolated pipx Environment: Fresh venv - Same error
  • UV Tool Environment: pydantic 2.11.7 (latest) - Same error

Dependency Versions Tested

  • ✅ pydantic 2.10.6 (user environment)
  • ✅ pydantic 2.11.7 (UV fresh environment)
  • ✅ pydantic-core 2.27.2 and 2.33.2
  • ✅ All latest compatible dependency versions

Impact

  • Severity: Critical - Complete failure to start
  • Scope: All installation methods on Python 3.12
  • Workaround: None available - package completely non-functional

Suggested Fix

Option 1: Add Missing Type Parameter

Modify the class definition to include the missing RequestT parameter:

# Current (broken):
class MCPServerContext(Context, Generic[ServerSessionT, LifespanContextT]):

# Suggested fix:
class MCPServerContext(Context, Generic[ServerSessionT, LifespanContextT, RequestT]):

Option 2: Review Type Parameter Requirements

Investigate if RequestT is actually needed by examining:

  1. The parent Context class definition
  2. Usage of type parameters throughout the class
  3. Whether the Generic parameters align with actual class usage

Option 3: Pydantic Compatibility Review

Ensure compatibility with pydantic 2.x model construction requirements for Generic classes.

Additional Context

Package Dependencies

intersystems-irispython>=5.1.0
mcp>=1.2.0
starlette>=0.36.0
uvicorn>=0.27.0
pydantic<3.0.0,>=2.7.2

Error Source

The error originates from pydantic's internal model construction (_model_construction.py) which validates Generic class definitions more strictly in recent versions.

Verification Steps for Fix

  1. Install the patched version
  2. Run python -m mcp_server_iris --help
  3. Verify successful startup and help display
  4. Test actual MCP server functionality with a client connection

Reporter Information

  • Testing Environment: Multiple clean environments to isolate the issue
  • Investigation Scope: Comprehensive testing across installation methods
  • Urgency: Blocking usage of mcp-server-iris entirely on Python 3.12

This bug completely prevents usage of mcp-server-iris v0.2.2 on Python 3.12 systems. The fix should be straightforward once the correct Generic type parameters are identified and added to the class definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions