-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support Python 3.9+ with optional MCP server support #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ryoppippi
merged 12 commits into
main
from
ENG-10906-ai-python-support-python-3-9-for-pydantic-sdk
Aug 26, 2025
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1a9bda2
fix: add type ignore for unreachable code in MCP server
ryoppippi f9d6988
docs: update README with Python version requirements
ryoppippi ccfd709
refactor: rename [server] to [mcp] for clarity
ryoppippi 4254aaf
fix: correct uv sync syntax in CI workflows
ryoppippi aa7f568
fix: add eval-type-backport for Python 3.9 Pydantic compatibility
ryoppippi 52bd25e
docs: add TODO comments for Python 3.9 compatibility code
ryoppippi 0e7fae6
fix: use Python 3.11 for docs build to support MCP examples
ryoppippi 0a14357
docs: quote extras in pip install commands to prevent shell globbing
ryoppippi c9df82a
security: fix SSRF vulnerability in URL path parameter replacement
ryoppippi 3eb2ea2
ci: add Python 3.11 support to lint workflow
ryoppippi 9f4024c
ci: update lint workflow to test Python 3.9 and 3.10
ryoppippi 03b8438
ci: fix versions
ryoppippi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ name = "stackone-ai" | |
| version = "0.3.1" | ||
| description = "agents performing actions on your SaaS" | ||
| readme = "README.md" | ||
| requires-python = ">=3.11" | ||
| requires-python = ">=3.9" | ||
| authors = [ | ||
| { name = "StackOne", email = "[email protected]" } | ||
| ] | ||
|
|
@@ -12,16 +12,21 @@ classifiers = [ | |
| "Intended Audience :: Developers", | ||
| "License :: OSI Approved :: MIT License", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.9", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Topic :: Software Development :: Libraries :: Python Modules", | ||
| ] | ||
| dependencies = [ | ||
| "pydantic>=2.10.6", | ||
| "requests>=2.32.3", | ||
| "langchain-core>=0.1.0", | ||
| "mcp[cli]>=1.3.0", | ||
| "bm25s>=0.2.2", | ||
| "numpy>=1.24.0", | ||
| "typing-extensions>=4.0.0", | ||
| "eval-type-backport; python_version<'3.10'", # TODO: Remove when Python 3.9 support is dropped | ||
| ] | ||
|
|
||
| [project.scripts] | ||
|
|
@@ -41,8 +46,12 @@ packages = ["stackone_ai"] | |
| "py.typed" = "py.typed" | ||
|
|
||
| [project.optional-dependencies] | ||
| # TODO: Remove python_version conditions when Python 3.9 support is dropped | ||
| mcp = [ | ||
| "mcp[cli]>=1.3.0; python_version>='3.10'", | ||
| ] | ||
| examples = [ | ||
| "crewai>=0.102.0", | ||
| "crewai>=0.102.0; python_version>='3.10'", | ||
| "langchain-openai>=0.3.6", | ||
| "openai>=1.63.2", | ||
| "python-dotenv>=1.0.1", | ||
|
|
@@ -82,7 +91,7 @@ markers = [ | |
|
|
||
| [tool.ruff] | ||
| line-length = 110 | ||
| target-version = "py311" | ||
| target-version = "py39" | ||
|
|
||
| [tool.ruff.lint] | ||
| select = [ | ||
|
|
@@ -96,7 +105,7 @@ select = [ | |
| ] | ||
|
|
||
| [tool.mypy] | ||
| python_version = "3.11" | ||
| python_version = "3.9" | ||
| disallow_untyped_defs = true | ||
| disallow_incomplete_defs = true | ||
| check_untyped_defs = true | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| # TODO: Remove when Python 3.9 support is dropped | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import base64 | ||
| import json | ||
| from collections.abc import Sequence | ||
| from enum import Enum | ||
| from functools import partial | ||
| from typing import Annotated, Any, TypeAlias, cast | ||
| from typing import Annotated, Any, cast | ||
| from urllib.parse import quote | ||
|
|
||
| import requests | ||
| from langchain_core.tools import BaseTool | ||
| from pydantic import BaseModel, BeforeValidator, Field, PrivateAttr | ||
| from requests.exceptions import RequestException | ||
|
|
||
| # TODO: Remove when Python 3.9 support is dropped | ||
| from typing_extensions import TypeAlias | ||
|
|
||
| # Type aliases for common types | ||
| JsonDict: TypeAlias = dict[str, Any] | ||
| Headers: TypeAlias = dict[str, str] | ||
|
|
@@ -140,21 +147,24 @@ def _prepare_request_params(self, kwargs: JsonDict) -> tuple[str, JsonDict, Json | |
| for key, value in kwargs.items(): | ||
| param_location = self._execute_config.parameter_locations.get(key) | ||
|
|
||
| match param_location: | ||
| case ParameterLocation.PATH: | ||
| url = url.replace(f"{{{key}}}", str(value)) | ||
| case ParameterLocation.QUERY: | ||
| if param_location == ParameterLocation.PATH: | ||
| # Safely encode path parameters to prevent SSRF attacks | ||
| encoded_value = quote(str(value), safe="") | ||
| url = url.replace(f"{{{key}}}", encoded_value) | ||
| elif param_location == ParameterLocation.QUERY: | ||
| query_params[key] = value | ||
| elif param_location in (ParameterLocation.BODY, ParameterLocation.FILE): | ||
| body_params[key] = value | ||
| else: | ||
| # Default behavior | ||
| if f"{{{key}}}" in url: | ||
| # Safely encode path parameters to prevent SSRF attacks | ||
| encoded_value = quote(str(value), safe="") | ||
| url = url.replace(f"{{{key}}}", encoded_value) | ||
| elif self._execute_config.method in {"GET", "DELETE"}: | ||
| query_params[key] = value | ||
| case ParameterLocation.BODY | ParameterLocation.FILE: | ||
| else: | ||
| body_params[key] = value | ||
| case _: | ||
| # Default behavior | ||
| if f"{{{key}}}" in url: | ||
| url = url.replace(f"{{{key}}}", str(value)) | ||
| elif self._execute_config.method in {"GET", "DELETE"}: | ||
| query_params[key] = value | ||
| else: | ||
| body_params[key] = value | ||
|
|
||
| return url, body_params, query_params | ||
|
|
||
|
|
@@ -355,13 +365,12 @@ def to_langchain(self) -> BaseTool: | |
| python_type: type = str # Default to str | ||
| if isinstance(details, dict): | ||
| type_str = details.get("type", "string") | ||
| match type_str: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not supported in 3.9 |
||
| case "number": | ||
| python_type = float | ||
| case "integer": | ||
| python_type = int | ||
| case "boolean": | ||
| python_type = bool | ||
| if type_str == "number": | ||
| python_type = float | ||
| elif type_str == "integer": | ||
| python_type = int | ||
| elif type_str == "boolean": | ||
| python_type = bool | ||
|
|
||
| field = Field(description=details.get("description", "")) | ||
| else: | ||
|
|
@@ -480,7 +489,7 @@ def to_langchain(self) -> Sequence[BaseTool]: | |
| """ | ||
| return [tool.to_langchain() for tool in self.tools] | ||
|
|
||
| def meta_tools(self) -> "Tools": | ||
| def meta_tools(self) -> Tools: | ||
| """Return meta tools for tool discovery and execution | ||
|
|
||
| Meta tools enable dynamic tool discovery and execution based on natural language queries. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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