Skip to content

Conversation

@ryoppippi
Copy link
Member

@ryoppippi ryoppippi commented Aug 26, 2025

Summary

  • Add Python 3.9+ support for core SDK functionality
  • Move MCP server to optional [mcp] extra requiring Python 3.10+
  • Update CI to test Python 3.9-3.13 with appropriate dependency sets

Background

Python 3.9 reaches end-of-life in October 2025, but the MCP SDK only supports Python 3.10+. To maximize compatibility while the transition happens, we've made MCP functionality optional.

Changes Made

Core Compatibility

  • Add from __future__ import annotations for modern type hint compatibility in Python 3.9
  • Replace match statements with if-elif chains for Python 3.9 compatibility
  • Use typing_extensions.TypeAlias for TypeAlias support in Python 3.9
  • Replace isinstance(x, dict | list) with isinstance(x, (dict, list))
  • Remove strict=False parameter from zip() (Python 3.10+ feature)

Dependency Management

  • Move mcp[cli] to optional [mcp] dependency with Python 3.10+ requirement
  • Move crewai to optional [examples] dependency with Python 3.10+ requirement
  • Add eval-type-backport for Python 3.9 Pydantic compatibility

Runtime Checks

  • Add Python version check in MCP server module with helpful error message
  • Graceful ImportError handling for optional dependencies

CI/CD Updates

  • Test Python 3.9-3.13 in CI matrix
  • Python 3.9 tests run with --all-extras --no-extra mcp to exclude MCP dependencies
  • Python 3.10+ tests run with --all-extras
  • Documentation build uses Python 3.11 to support MCP examples

Documentation

  • Update README with Python version requirements
  • Add installation instructions for optional features
  • Add TODO comments for future cleanup when Python 3.9 support is dropped

Breaking Changes

  • MCP server functionality now requires explicit installation: pip install 'stackone-ai[mcp]'
  • CrewAI examples require Python 3.10+: pip install 'stackone-ai[examples]'

Future Refactoring

Added comprehensive TODO comments throughout the codebase to make it easy to refactor when Python 3.9 support is dropped (October 2025 EOL). Search for "TODO: Remove when Python 3.9 support is dropped" to find all compatibility code that can be cleaned up.

Test Plan

  • Python 3.9: Core SDK functionality (without MCP/CrewAI)
  • Python 3.10+: Full functionality including MCP server and CrewAI
  • All existing tests pass
  • Linting and type checking passes
  • CI validation across Python 3.9-3.13

This is needed because mypy sees the Python version check as always false
when running on Python 3.10+, making the subsequent code unreachable.
The code is actually reachable at runtime when Python 3.10+ is used.
- Add Requirements section with Python 3.9+ for core SDK
- Add installation options for optional features
- Document MCP server requiring Python 3.10+
- Add note about CrewAI requiring Python 3.10+
- Rename optional dependency group from 'server' to 'mcp' for better clarity
- Update CI workflows to use --without mcp instead of --without server
- Update README installation instructions
- Update error message in MCP server module
Use --all-extras --no-extra mcp instead of --without-group mcp
for excluding optional dependencies in uv sync command.
- Add eval-type-backport dependency for Python <3.10 to handle union types
- Fix mypy exclusion syntax for server.py when MCP is not available
python_type: type = str # Default to str
if isinstance(details, dict):
type_str = details.get("type", "string")
match type_str:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not supported in 3.9

- Add TODO for zip strict parameter
- Add TODO for eval-type-backport dependency
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

10 issues found across 11 files

Linked issue analysis

Linked issue: ENG-10906: [ai-python]: support python3.9 for pydantic sdk

Status Acceptance criteria Notes
Downgrade supported Python version to >=3.9 in packaging Changed requires-python to >=3.9 in pyproject.toml
Make MCP server an optional extra requiring Python 3.10+ Moved mcp into optional deps with python_version guard
Guard MCP server code to require Python 3.10+ and surface helpful error if MCP not installed Added runtime version check and ImportError message in server.py
Replace Python 3.10-only syntax in core SDK to be compatible with Python 3.9 Replaced match/case and | unions in core files where needed
Add typing-extensions and __future__ annotations as needed for Python 3.9 compatibility Added __future__ imports and typing_extensions TypeAlias
Update CI to test Python 3.9-3.13 with appropriate dependency sets per version Test matrix added for 3.9-3.13 and per-version extras
Verify core SDK works on Python 3.9 without MCP (Test plan) CI will run 3.9 with --without mcp and core code adjusted
Verify MCP functionality works on Python 3.10+ (Test plan) CI will run 3.10+ with all extras and server guarded for 3.10+
Update README/docs to document requirements and optional extras README updated with Requirements and optional install snippets
Update ruff and mypy config to target Python 3.9 ruff target-version and mypy python_version set to 3.9

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

README.md Outdated

CrewAI uses LangChain tools natively, making integration seamless:

> **Note**: CrewAI requires Python 3.10+. Install with `pip install stackone-ai[examples]`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote extras in the inline pip install example to avoid shell globbing issues in zsh and similar shells.

Prompt for AI agents
Address the following comment on README.md at line 109:

<comment>Quote extras in the inline pip install example to avoid shell globbing issues in zsh and similar shells.</comment>

<file context>
@@ -82,10 +102,12 @@ for tool_call in response.tool_calls:
 &lt;/details&gt;
 
 &lt;details&gt;
-&lt;summary&gt;CrewAI Integration&lt;/summary&gt;
+&lt;summary&gt;CrewAI Integration (Python 3.10+)&lt;/summary&gt;
 
 CrewAI uses LangChain tools natively, making integration seamless:
 
+&gt; **Note**: CrewAI requires Python 3.10+. Install with `pip install stackone-ai[examples]`
</file context>
Suggested change
> **Note**: CrewAI requires Python 3.10+. Install with `pip install stackone-ai[examples]`
> **Note**: CrewAI requires Python 3.10+. Install with `pip install "stackone-ai[examples]"`

README.md Outdated
pip install stackone-ai[examples]

# Install everything
pip install stackone-ai[mcp,examples]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote combined extras in pip install to avoid shell globbing issues.

Prompt for AI agents
Address the following comment on README.md at line 44:

<comment>Quote combined extras in pip install to avoid shell globbing issues.</comment>

<file context>
@@ -18,12 +18,32 @@ StackOne AI provides a unified interface for accessing various SaaS tools throug
   - CrewAI Tools
   - LangGraph Tool Node
 
+## Requirements
+
+- Python 3.9+ (core SDK functionality)
+- Python 3.10+ (for MCP server and CrewAI examples)
+
 ## Installation
</file context>
Suggested change
pip install stackone-ai[mcp,examples]
pip install "stackone-ai[mcp,examples]"

README.md Outdated
pip install stackone-ai[mcp]

# Install with CrewAI examples (requires Python 3.10+)
pip install stackone-ai[examples]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote extras in pip install to prevent shell globbing errors in some shells.

Prompt for AI agents
Address the following comment on README.md at line 41:

<comment>Quote extras in pip install to prevent shell globbing errors in some shells.</comment>

<file context>
@@ -18,12 +18,32 @@ StackOne AI provides a unified interface for accessing various SaaS tools throug
   - CrewAI Tools
   - LangGraph Tool Node
 
+## Requirements
+
+- Python 3.9+ (core SDK functionality)
+- Python 3.10+ (for MCP server and CrewAI examples)
+
 ## Installation
</file context>
Suggested change
pip install stackone-ai[examples]
pip install "stackone-ai[examples]"

README.md Outdated

```bash
# Install with MCP server support (requires Python 3.10+)
pip install stackone-ai[mcp]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote extras in pip install to avoid shell globbing (e.g., zsh) causing 'no matches found'.

Prompt for AI agents
Address the following comment on README.md at line 38:

<comment>Quote extras in pip install to avoid shell globbing (e.g., zsh) causing &#39;no matches found&#39;.</comment>

<file context>
@@ -18,12 +18,32 @@ StackOne AI provides a unified interface for accessing various SaaS tools throug
   - CrewAI Tools
   - LangGraph Tool Node
 
+## Requirements
+
+- Python 3.9+ (core SDK functionality)
+- Python 3.10+ (for MCP server and CrewAI examples)
+
 ## Installation
</file context>
Suggested change
pip install stackone-ai[mcp]
pip install "stackone-ai[mcp]"

The build_docs.py script requires Python 3.11+ and processes MCP examples,
so we need Python 3.11 with all extras for proper documentation generation.
- Add quotes around extras in all pip install examples
- Prevents 'no matches found' errors in zsh and similar shells
- Affects both installation section and inline examples
- Add urllib.parse.quote to safely encode path parameters
- Use safe='' to encode all special characters including '/', ':', '@'
- Prevents attackers from injecting malicious hosts or internal service paths
- Applies to both explicit PATH parameters and default path replacement logic
- Add matrix strategy to test both Python 3.9 and 3.11
- Configure appropriate dependency installation for each version
- Python 3.9: excludes MCP extras (not supported)
- Python 3.11: includes all extras for full coverage
- Aligns with existing test workflow pattern for consistency
- Change from 3.9/3.11 matrix to 3.9/3.10 for better coverage
- Maintains appropriate dependency configurations for each version
Copy link
Contributor

@glebedel glebedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 13 to 24
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- python-version: "3.9"
test-extras: "--all-extras --no-extra mcp"
- python-version: "3.10"
test-extras: "--all-extras"
- python-version: "3.11"
test-extras: "--all-extras"
- python-version: "3.12"
test-extras: "--all-extras"
- python-version: "3.13"
test-extras: "--all-extras"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need all of these, can we just do 3.9 & 3.10 assuming backwards compatibility ? Maybe 3.9/3.10 & the latest LTE

Copy link
Member Author

@ryoppippi ryoppippi Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh 3.14 is the latest

@glebedel glebedel closed this Aug 26, 2025
@glebedel glebedel reopened this Aug 26, 2025
@glebedel glebedel closed this Aug 26, 2025
@glebedel glebedel reopened this Aug 26, 2025
@ryoppippi ryoppippi force-pushed the ENG-10906-ai-python-support-python-3-9-for-pydantic-sdk branch from 2f29b4c to 03b8438 Compare August 26, 2025 15:32
@ryoppippi ryoppippi enabled auto-merge (squash) August 26, 2025 15:32
@ryoppippi ryoppippi merged commit 1a37776 into main Aug 26, 2025
5 checks passed
@ryoppippi ryoppippi deleted the ENG-10906-ai-python-support-python-3-9-for-pydantic-sdk branch August 26, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants