-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add MCP-backed dynamic tool fetching to Python SDK #39
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,18 +1,52 @@ | ||||||
| # TODO: Remove when Python 3.9 support is dropped | ||||||
| from __future__ import annotations | ||||||
|
|
||||||
| import asyncio | ||||||
| import base64 | ||||||
| import fnmatch | ||||||
| import json | ||||||
| import os | ||||||
| import threading | ||||||
| import warnings | ||||||
| from typing import Any | ||||||
| from collections.abc import Coroutine | ||||||
| from dataclasses import dataclass | ||||||
| from importlib import metadata | ||||||
| from typing import Any, TypeVar | ||||||
|
|
||||||
| from stackone_ai.constants import OAS_DIR | ||||||
| from stackone_ai.models import ( | ||||||
| ExecuteConfig, | ||||||
| ParameterLocation, | ||||||
| StackOneTool, | ||||||
| ToolParameters, | ||||||
| Tools, | ||||||
| ) | ||||||
| from stackone_ai.specs.parser import OpenAPIParser | ||||||
|
|
||||||
| try: | ||||||
| _SDK_VERSION = metadata.version("stackone-ai") | ||||||
| except metadata.PackageNotFoundError: # pragma: no cover - best-effort fallback when running from source | ||||||
| _SDK_VERSION = "dev" | ||||||
|
|
||||||
| DEFAULT_BASE_URL = "https://api.stackone.com" | ||||||
| _RPC_PARAMETER_LOCATIONS = { | ||||||
| "action": ParameterLocation.BODY, | ||||||
| "body": ParameterLocation.BODY, | ||||||
| "headers": ParameterLocation.BODY, | ||||||
| "path": ParameterLocation.BODY, | ||||||
| "query": ParameterLocation.BODY, | ||||||
| } | ||||||
| _USER_AGENT = f"stackone-ai-python/{_SDK_VERSION}" | ||||||
|
|
||||||
| T = TypeVar("T") | ||||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class _McpToolDefinition: | ||||||
| name: str | ||||||
| description: str | None | ||||||
| input_schema: dict[str, Any] | ||||||
|
|
||||||
|
|
||||||
| class ToolsetError(Exception): | ||||||
| """Base exception for toolset errors""" | ||||||
|
|
@@ -32,6 +66,166 @@ class ToolsetLoadError(ToolsetError): | |||||
| pass | ||||||
|
|
||||||
|
|
||||||
| def _run_async(awaitable: Coroutine[Any, Any, T]) -> T: | ||||||
| """Run a coroutine, even when called from an existing event loop.""" | ||||||
|
|
||||||
| try: | ||||||
| asyncio.get_running_loop() | ||||||
| except RuntimeError: | ||||||
| return asyncio.run(awaitable) | ||||||
|
|
||||||
| result: dict[str, T] = {} | ||||||
| error: dict[str, BaseException] = {} | ||||||
|
|
||||||
| def runner() -> None: | ||||||
| try: | ||||||
| result["value"] = asyncio.run(awaitable) | ||||||
| except BaseException as exc: # pragma: no cover - surfaced in caller context | ||||||
|
||||||
| except BaseException as exc: # pragma: no cover - surfaced in caller context | |
| except Exception as exc: # pragma: no cover - surfaced in caller context |
Copilot
AI
Nov 11, 2025
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.
The import path mcp.client.streamable_http appears to be incorrect. Based on the MCP Python SDK package structure, this should be mcp.client.streamablehttp (without the underscore). The correct import should be from mcp.client.streamablehttp import streamablehttp_client.
| from mcp.client.streamable_http import streamablehttp_client | |
| from mcp.client.streamablehttp import streamablehttp_client |
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.
never heard of these they good?
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.
https://docs.python.org/3/library/collections.abc.html#collections.abc.Coroutine