Skip to content

feat: Async Rust OCR Bridge and MCP OAuth UI Restore - #31453

Merged
45 commits merged into
BerriAI:litellm_internal_stagingfrom
ArjunPakhan:feat/restore-mcp-oauth-ui
Aug 17, 2026
Merged

feat: Async Rust OCR Bridge and MCP OAuth UI Restore#31453
45 commits merged into
BerriAI:litellm_internal_stagingfrom
ArjunPakhan:feat/restore-mcp-oauth-ui

Conversation

@ArjunPakhan

@ArjunPakhan ArjunPakhan commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR combines frontend layout restoration for the MCP OAuth credentials view alongside core backend updates transitioning the Rust OCR infrastructure to an async architecture.

Changes

  • UI: Implemented missing MCPCredentialsTab.tsx layout and stitched component states inside mcp_servers.tsx.
  • OCR Backend: Reimplemented aocr() as a native async function and extracted shared request preparation logic via _prepare_ocr_request.
  • Rust Bridge: Migrated Rust OCR module from blocking to async reqwest, added compile-time provider code generation in crates/core/build.rs, and introduced a defensive getattr loader pattern to prevent attribute failures.

Pre-Submission checklist

  • My PR passes all CI/CD checks
  • I have addressed the Greptile review comments regarding load_rust_ocr safety.

shin-berri and others added 30 commits May 13, 2026 22:37
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
Adds a quickstart for the two published Terraform modules on the public
registry (BerriAI/litellm/aws and BerriAI/litellm/google). Copy-paste
main.tf for each cloud, the one-time GCP Artifact Registry remote-repo
command, and pointers to the registry pages for the full input surface.

Sits inside the Get Started section, between the gateway/SDK table and
Run in Developer Mode -- where someone scanning the README for "how do I
deploy this" will land.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
GCP gets the real 1-click: Open in Cloud Shell badge that clones the repo
and walks through `terraform apply` via the existing DeployStack
tutorial (already shipped at terraform/litellm/gcp/examples/default/
TUTORIAL.md). User just picks a project.

AWS gets a soft 1-click: a Launch in AWS CloudShell badge that opens an
in-browser, already-authenticated shell. User runs four commands
(clone + cd + cp tfvars + terraform apply) once inside. There's no
native AWS deeplink that pre-clones a repo + runs a tutorial -- CFN
"Launch Stack" + CodeBuild would be needed for that, and that's a
separate piece of work.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…on font

GitHub rewrites an image's height attribute to "height: auto; max-height: Npx", which only caps and never stretches, so each image renders at its intrinsic height. The AWS/GCP shields badges are intrinsically 28px while the Render/Railway buttons are 40px, leaving the row uneven regardless of the height="48" we set. Replace the two shields badges with committed 40px PNGs so all four header buttons render at the same 40px.

Also swap the Cloud Shell button from open-btn.svg to open-btn.png. The SVG renders its label as live text with font-family "Roboto, Sans" and no generic fallback; since neither font exists in GitHub's render environment, the text fell back to a serif (Times New Roman). The PNG bakes in the correct typeface.
The Railway button wrapped its img across indented lines, so the anchor contained leading and trailing whitespace. GitHub underlines link content, rendering that whitespace as a small blue underline beside the button. Put the anchor on one line like the other three buttons so there is no inner whitespace to underline.
Backports only the model map changes from BerriAI#30064 so deployments on
released litellm versions pick up Fable 5 pricing, context window, and
the adaptive thinking flag through the hosted cost map fetch without
upgrading. Includes the supports_sampling_params flag on the 28
Fable 5 / Opus 4.7 / Opus 4.8 entries (ignored by released code, read
by the gating that ships with the next release) and the matching
one-line schema declaration so the map validation test passes.

https://claude.ai/code/session_01MZarYYT3aS7DxaNjoax6Gm
…cost_map

Add Claude Fable 5 cost map entries (data-only hotfix for the hosted map)
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
@ArjunPakhan
ArjunPakhan requested a review from a team June 26, 2026 13:28
@CLAassistant

CLAassistant commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 8 committers have signed the CLA.

✅ yuneng-berri
✅ ArjunPakhan
✅ mateo-berri
❌ shin-berri
❌ claude
❌ yassin-berriai
❌ krrish-berri-2
❌ ishaan-berri
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors the LiteLLM OCR infrastructure to support an async Rust bridge path alongside the existing sync one, and introduces compile-time provider code generation from provider_endpoints_support.json. Despite the PR title claiming a UI fix for the MCP OAuth credentials tab, no UI files are changed — the entire diff is backend OCR and Rust bridge work.

  • aocr() is reimplemented as a native async function (no longer a thread-pool wrapper around ocr()), and the shared _prepare_ocr_request helper is extracted to avoid duplicating provider resolution and param-mapping between the sync and async paths.
  • The Rust OCR module migrates from blocking reqwest to async, adds multi-provider dispatch via ocr_config_for, and exposes a new aocr PyO3 entry-point; the build.rs for litellm-core now code-generates the full LlmProvider enum and static metadata from the root provider_endpoints_support.json at compile time.

Confidence Score: 3/5

Do not merge until the PR description and title are reconciled with the actual changes — it currently claims to fix an MCP OAuth UI issue but contains only OCR and Rust bridge changes.

The OCR refactoring itself is well-structured with shared request preparation, proper async Rust bridge, defensive getattr in the async loader, and comprehensive mock tests. The main blocker is that the PR metadata points to a completely different feature, so the claimed issue #31253 has no evidence of being resolved and the wrong issue may be closed on merge.

litellm/ocr/main.py (PR description mismatch, core logic change); litellm/ocr/rust_bridge.py (minor inconsistency in load_rust_ocr attribute access); litellm-rust/crates/core/src/providers/README.md (new doc file per repo rules).

Important Files Changed

Filename Overview
litellm/ocr/main.py Major refactor: extracted shared _prepare_ocr_request helper used by both ocr() and aocr(); aocr now has its own async implementation instead of delegating to the sync path via thread-pool; PR description does not match these changes.
litellm/ocr/rust_bridge.py Added RustAocr protocol, load_rust_aocr(), and aocr param on use_litellm_rust(); load_rust_ocr() inconsistently uses direct attribute access instead of the defensive getattr pattern used by load_rust_aocr().
litellm-rust/crates/providers/src/ocr.rs Migrated from blocking to async reqwest client; added multi-provider dispatch via ocr_config_for; extra_headers support with case-insensitive Authorization de-duplication; Mistral URL/key resolution is still hardcoded with a TODO for future generalization.
litellm-rust/crates/python-bridge/src/lib.rs Added aocr Python-callable async function alongside existing sync ocr; marshalling helpers extracted; block_on used for sync path via pyo3_async_runtimes::tokio::get_runtime().
litellm-rust/crates/core/build.rs New build script that generates the LlmProvider enum and static metadata from provider_endpoints_support.json at compile time; validates uniqueness and non-empty display names/URLs; includes self-consistency tests in generated code.
tests/test_litellm/ocr/test_rust_bridge.py Significantly expanded with RecordingAsyncBridge, RaisingBridge/RaisingAsyncBridge, build_prepared_request factory, and new async test cases; all tests use mocks with no real network calls.
provider_endpoints_support.json Added default_creds section with Mistral's default API base; added missing url fields for apertis, chutes, nanogpt, poe, and synthetic providers needed by the new build.rs.
litellm/llms/base_llm/ocr/transformation.py Added get_api_key_env_var() hook to base class returning None; allows provider subclasses to expose their key env var name for use by the Rust bridge resolver.
litellm/llms/mistral/ocr/transformation.py Introduced MISTRAL_OCR_API_KEY_ENV_VAR constant and overrides get_api_key_env_var() to return it; refactors inline string literal to use the constant.
litellm/proxy/ocr_endpoints/endpoints.py Converted top-level import of convert_file_document_to_url_document / get_mime_type to a lazy local import inside _build_document_from_upload, breaking a potential import cycle.

Comments Outside Diff (1)

  1. litellm/ocr/main.py, line 694 (link)

    P1 PR description does not match the code changes

    The PR title is "feat(ui): restore mcp oauth credentials tab layout" and the description references closing feat: make rust OCR async-first #31253 (a UI issue about MCPCredentialsTab.tsx). However, none of the 23 changed files contain any frontend or UI code — every change is OCR infrastructure: async Rust bridge, _prepare_ocr_request extraction, provider code generation from build.rs, and related tests. There is no MCPCredentialsTab.tsx change anywhere in the diff.

    Per the team rule, a PR claiming to fix a specific issue must include evidence that the issue is resolved. As written, this PR either has the wrong description or the wrong code changes attached to it.

    Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix(deps): bump langgraph-checkpoint to ..." | Re-trigger Greptile

Comment on lines +1 to +19
# Rust Provider Metadata

The repo-root `provider_endpoints_support.json` is the shared source of truth
for provider identity and docs metadata in `litellm-rust`. `crates/core/build.rs`
reads it at compile time and generates the typed `LlmProvider` enum plus static
provider metadata. Runtime code does not parse this JSON.

To add a provider:

- Add a `provider_endpoints_support.json` provider entry using the LiteLLM
provider slug, display name, docs URL, and endpoint support flags.
- Add optional defaults under the top-level `default_creds` map only when there
is a stable provider-level base URL. Keep route-specific key env var names in
the provider transform/config so auth resolution has one owner.
- Put request/response logic under
`crates/providers/src/<provider>/<route>/transformation.rs`; do not put
transforms, signing logic, or secrets in provider metadata.
- Run `cargo test -p litellm-core --locked`; it verifies the Rust registry stays
in parity with `provider_endpoints_support.json`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 New documentation file added inside the main repo

crates/core/src/providers/README.md is a newly added documentation file. The team rule requires documentation to live in the litellm-docs repo rather than this one. If this is intended as developer-only contributing guidance for the Rust crate, please clarify — otherwise it should be moved to the docs repo or removed.

Rule Used: Prevent documentation from being added - needs to ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread litellm/ocr/rust_bridge.py Outdated
@@ -72,3 +98,14 @@ def load_rust_ocr() -> RustOcr | None:
except ImportError:
return None
return cast(RustOcr, litellm_python_bridge.ocr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 load_rust_ocr() accesses litellm_python_bridge.ocr as a direct attribute, which raises AttributeError if the compiled extension was built without that symbol. The newer load_rust_aocr() is defensive and uses getattr(..., "aocr", None). Applying the same pattern to load_rust_ocr() keeps both loaders consistent and prevents hard failures if the native extension is partially built or from an older version.

Suggested change
return cast(RustOcr, litellm_python_bridge.ocr)
return cast(RustOcr, getattr(litellm_python_bridge, "ocr", None))

@ArjunPakhan ArjunPakhan changed the title feat(ui): restore mcp oauth credentials tab layout feat: Async Rust OCR Bridge and MCP OAuth UI Restore Jun 26, 2026
@mateo-berri mateo-berri closed this pull request by merging all changes into BerriAI:litellm_internal_staging in 41c3133 Aug 17, 2026
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.

9 participants