Skip to content

Update Anthropic and OpenAI clients to use Omit instead of NotGiven#3088

Merged
jlowin merged 3 commits intomainfrom
claude/investigate-dependency-failure-omTg7
Feb 5, 2026
Merged

Update Anthropic and OpenAI clients to use Omit instead of NotGiven#3088
jlowin merged 3 commits intomainfrom
claude/investigate-dependency-failure-omTg7

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Feb 5, 2026

Description

This PR updates the Anthropic and OpenAI sampling handlers to use the newer Omit type and omit sentinel value instead of the deprecated NotGiven and NOT_GIVEN from their respective SDK versions.

Changes Made

Anthropic Handler (src/fastmcp/client/sampling/handlers/anthropic.py)

  • Replaced NotGiven import with Omit
  • Replaced NOT_GIVEN import with omit from anthropic._types
  • Updated all type annotations from NotGiven to Omit
  • Updated all sentinel value assignments from NOT_GIVEN to omit
  • Simplified conditional expressions for better readability

OpenAI Handler (src/fastmcp/client/sampling/handlers/openai.py)

  • Replaced NotGiven and NOT_GIVEN imports with Omit and omit
  • Updated all type annotations from NotGiven to Omit
  • Updated all sentinel value assignments from NOT_GIVEN to omit

Test Updates (tests/server/providers/openapi/test_openapi_performance.py)

  • Added Any type import for proper type hints
  • Added explicit type annotation dict[str, Any] to schema variable
  • Removed unnecessary # type: ignore[index] comment

Rationale

The Omit type and omit sentinel are the current recommended approach in both Anthropic and OpenAI SDKs for indicating that optional parameters should be omitted from API requests. This change ensures compatibility with newer SDK versions and follows the libraries' current best practices.

Contributors Checklist

  • My change closes #(issue number)
  • I have followed the repository's development workflow
  • I have tested my changes manually and by adding relevant tests
  • I have performed all required documentation updates

Review Checklist

  • I have self-reviewed my changes
  • My Pull Request is ready for review

https://claude.ai/code/session_01Fs5vHiWaUebe826pGq4eCN

@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. client Related to the FastMCP client SDK or client-side functionality. labels Feb 5, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8033e82710

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +22 to +23
from anthropic import AsyncAnthropic, Omit
from anthropic._types import omit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve compatibility with supported Anthropic versions

The new import path requires Omit/omit, but this module still advertises support for anthropic>=0.40.0 in pyproject.toml; earlier releases in that range only expose the older NotGiven API, so importing this handler will raise ImportError even when users satisfy FastMCP's declared dependency floor. This makes the Anthropic sampling handler unusable for a subset of supported installations unless you either raise the minimum version or provide a fallback import path.

Useful? React with 👍 / 👎.

@marvin-context-protocol
Copy link
Copy Markdown
Contributor

marvin-context-protocol Bot commented Feb 5, 2026

Test Failure Analysis

Summary: The "Tests with lowest-direct dependencies" job failed because Omit and omit types do not exist in the minimum required versions of the Anthropic (≥0.40.0) and OpenAI (≥1.102.0) SDKs.

Root Cause: The PR updates the sampling handlers to use the newer Omit type and omit sentinel value instead of NotGiven and NOT_GIVEN. However:

  • Anthropic SDK: Omit was made public in version 0.41.0, but pyproject.toml allows ≥0.40.0
  • OpenAI SDK: The minimum version is ≥1.102.0, but Omit and omit were introduced in a later version

The lowest-direct resolution strategy installs the minimum compatible versions, which do not have these newer types.

Suggested Solution: Update the minimum version requirements in pyproject.toml:

[project.optional-dependencies]
anthropic = ["anthropic>=0.41.0"]  # Changed from 0.40.0
openai = ["openai>=1.54.0"]        # Needs verification of exact version

Action Items:

  1. Verify the exact OpenAI SDK version that introduced Omit and omit (likely 1.54.0 or later)
  2. Update pyproject.toml line 54-55 with the corrected minimum versions
  3. Re-run tests to confirm compatibility
Detailed Analysis

Error Log Excerpts

Anthropic Handler Import Error:

src/fastmcp/client/sampling/handlers/anthropic.py:22: in <module>
    from anthropic import AsyncAnthropic, Omit
E   ImportError: cannot import name 'Omit' from 'anthropic'

OpenAI Handler Import Error:

src/fastmcp/client/sampling/handlers/openai.py:25: in <module>
    from openai._types import omit
E   ImportError: cannot import name 'omit' from 'openai._types'

Version Research

According to the Anthropic SDK PyPI release, version 0.41.0 (released December 2024) included the change "make the Omit type public (#772)".

The OpenAI SDK appears to have introduced Omit and omit around version 1.54.0, though the exact version needs verification from the changelog.

Related Files
  • pyproject.toml:54-55: Contains the minimum version constraints that need updating
  • src/fastmcp/client/sampling/handlers/anthropic.py:22-23: Imports Omit and omit from Anthropic SDK
  • src/fastmcp/client/sampling/handlers/openai.py:24-25: Imports Omit and omit from OpenAI SDK
  • .github/workflows/run-tests.yml:55-74: Defines the lowest-direct dependencies test job

Comment updated to reflect the latest analysis. The test failure is due to incompatible minimum dependency versions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 5, 2026

Walkthrough

Replaces sentinel-based handling (NotGiven/NOT_GIVEN) in Anthropic and OpenAI sampling handlers with dynamic kwargs construction that only includes fields when their values are non-None. Defaults and internal logic were changed from NotGiven to None, toolChoice "none" is normalized to None (omitting tools), and requests are built into a kwargs dict (model, messages, max_tokens always present) with optional keys (system, temperature, stop_sequences/stop, tools, tool_choice) added conditionally before calling create(**kwargs). This shifts how absent optional fields appear in requests.

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides clear details of changes, rationale, and affected files; however, the Contributors Checklist items are unchecked and the PR appears incomplete against the template requirements. Check all required checklist items (closing issue, following workflow, testing, documentation, self-review) to indicate the PR is ready for review, or provide explanations for any items that don't apply.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating clients to use Omit instead of NotGiven for better SDK compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/investigate-dependency-failure-omTg7

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment on lines +21 to +23
try:
from anthropic import AsyncAnthropic, NotGiven
from anthropic._types import NOT_GIVEN
from anthropic import AsyncAnthropic, Omit
from anthropic._types import omit
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for anthropic version constraints in dependency files
rg -n --glob 'pyproject.toml' --glob 'requirements*.txt' --glob 'setup.cfg' --glob 'setup.py' 'anthropic'

Repository: jlowin/fastmcp

Length of output: 166


🏁 Script executed:

#!/bin/bash
# Check the actual imports at lines 21-23
head -n 30 src/fastmcp/client/sampling/handlers/anthropic.py | tail -n +15

Repository: jlowin/fastmcp

Length of output: 384


🏁 Script executed:

#!/bin/bash
# List potential dependency files to ensure we capture all
fd -t f -E '.git' -E '__pycache__' \( -name 'pyproject.toml' -o -name 'requirements*.txt' -o -name 'setup.py' -o -name 'setup.cfg' -o -name 'uv.lock' -o -name 'poetry.lock' \)

Repository: jlowin/fastmcp

Length of output: 288


🌐 Web query:

anthropic SDK Omit omit type introduction version

💡 Result:

In Anthropic’s Python SDK (anthropic), Omit is a sentinel type (paired with NotGiven) used to explicitly omit values—most notably to remove default headers/query params when building a request. (deepwiki.com)

The first release note that explicitly calls out adopting Omit in public type signatures is anthropic v0.68.1 (2025-09-26): “types: change optional parameter type from NotGiven to Omit”. (newreleases.io)

Citations:


🏁 Script executed:

#!/bin/bash
# Get the full try-except block to see error handling
sed -n '21,40p' src/fastmcp/client/sampling/handlers/anthropic.py

Repository: jlowin/fastmcp

Length of output: 737


🏁 Script executed:

#!/bin/bash
# Get more of the except block
sed -n '38,45p' src/fastmcp/client/sampling/handlers/anthropic.py

Repository: jlowin/fastmcp

Length of output: 312


Bump minimum Anthropic SDK version to 0.68.1 or later.

The Omit type and omit function were introduced in Anthropic SDK v0.68.1. The current constraint allows anthropic>=0.40.0, which will fail at runtime on any version below v0.68.1 with an uninformative import error. Update pyproject.toml line 54 to specify anthropic>=0.68.1.

Comment thread src/fastmcp/client/sampling/handlers/openai.py Outdated
@jlowin jlowin merged commit db650ca into main Feb 5, 2026
11 checks passed
@jlowin jlowin deleted the claude/investigate-dependency-failure-omTg7 branch February 5, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Related to the FastMCP client SDK or client-side functionality. enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants