Skip to content

Replace requests with httpx #25

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
merged 4 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion python/thirdweb-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies = [
"jsonref>=1.1.0,<2",
"httpx>=0.28.1,<0.29",
"aiohttp>=3.11.14",
"requests>=2.32.3",
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion python/thirdweb-ai/src/thirdweb_ai/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, base_url: str, secret_key: str, httpx_client: httpx.Client |
self.base_url = base_url
self.secret_key = secret_key
self.client = (
httpx_client if httpx_client else httpx.Client(timeout=120.0, transport=httpx.HTTPTransport(retries=5))
httpx_client or httpx.Client(timeout=120.0, transport=httpx.HTTPTransport(retries=5))
)

def _make_headers(self):
Expand Down
4 changes: 1 addition & 3 deletions python/thirdweb-ai/src/thirdweb_ai/services/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import Annotated, Any

import requests
from pydantic import BaseModel

from thirdweb_ai.services.service import Service
Expand Down Expand Up @@ -75,10 +74,9 @@ def _get_file(self, path: str, params: dict[str, Any] | None = None, headers: di
def _post_file(self, url: str, files: dict[str, Any]) -> dict[str, Any]:
"""Post files to a URL with proper authorization headers."""
headers = self._make_headers()
# Remove the Content-Type as requests will set it correctly for multipart/form-data
headers.pop("Content-Type", None)

response = requests.post(url, files=files, headers=headers)
response = self.client.post(url, files=files, headers=headers)
response.raise_for_status()
return response.json()

Expand Down
4 changes: 1 addition & 3 deletions python/thirdweb-ai/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/thirdweb-mcp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "thirdweb-mcp"
version = "0.1.12"
version = "0.1.13"
description = "thirdweb MCP"
authors = [{ name = "thirdweb", email = "[email protected]" }]
requires-python = "~=3.10"
Expand Down
13 changes: 9 additions & 4 deletions python/thirdweb-mcp/src/mcp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

import click
from mcp.server.fastmcp import FastMCP
from thirdweb_ai import Engine, Insight, Nebula
from thirdweb_ai import Engine, Insight, Nebula, Storage
from thirdweb_ai.adapters.mcp import add_fastmcp_tools

from mcp.server.fastmcp import FastMCP


@click.command()
@click.option(
Expand All @@ -25,7 +26,7 @@
"--secret-key",
type=str,
default=lambda: os.getenv("THIRDWEB_SECRET_KEY"),
help="Your thirdweb API secret key for authentication. Required for nebula and insight services. Can be obtained from the thirdweb dashboard. Falls back to THIRDWEB_SECRET_KEY environment variable if not specified.",
help="Your thirdweb API secret key for authentication. Required for nebula, insight, and storage services. Can be obtained from the thirdweb dashboard. Falls back to THIRDWEB_SECRET_KEY environment variable if not specified.",
)
@click.option(
"--chain-id",
Expand Down Expand Up @@ -69,7 +70,7 @@ def main(
# determine which services to enable based on the provided options
services = []
if secret_key:
services.extend(["nebula", "insight"])
services.extend(["nebula", "insight", "storage"])

if engine_url and engine_auth_jwt:
services.append("engine")
Expand All @@ -88,6 +89,10 @@ def main(
insight = Insight(secret_key=secret_key, chain_id=chain_ids)
add_fastmcp_tools(mcp, insight.get_tools())

if "storage" in services:
storage = Storage(secret_key=secret_key)
add_fastmcp_tools(mcp, storage.get_tools())

if "engine" in services:
engine = Engine(
engine_url=engine_url,
Expand Down