sample_id
stringlengths
21
196
text
stringlengths
105
936k
metadata
dict
category
stringclasses
6 values
PrefectHQ/fastmcp:src/fastmcp/server/auth/authorization.py
"""Authorization checks for FastMCP components. This module provides callable-based authorization for tools, resources, and prompts. Auth checks are functions that receive an AuthContext and return True to allow access or False to deny. Auth checks can also raise exceptions: - AuthorizationError: Propagates with the ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/auth/authorization.py", "license": "Apache License 2.0", "lines": 136, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:src/fastmcp/server/middleware/authorization.py
"""Authorization middleware for FastMCP. This module provides middleware-based authorization using callable auth checks. AuthMiddleware applies auth checks globally to all components on the server. Example: ```python from fastmcp import FastMCP from fastmcp.server.auth import require_scopes, restrict_tag ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/middleware/authorization.py", "license": "Apache License 2.0", "lines": 261, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/server/auth/test_authorization.py
"""Tests for authorization checks and AuthMiddleware.""" from unittest.mock import Mock import mcp.types as mcp_types import pytest from mcp.server.auth.middleware.auth_context import auth_context_var from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser from fastmcp import FastMCP from fastmcp.client...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/auth/test_authorization.py", "license": "Apache License 2.0", "lines": 621, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/integration_tests/test_timeout_fix.py
"""Test that verifies the timeout fix for issue #2842 and #2845.""" import asyncio import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.transports import StreamableHttpTransport from fastmcp.utilities.tests import run_server_async def create_test_server() -> FastMCP: ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/integration_tests/test_timeout_fix.py", "license": "Apache License 2.0", "lines": 38, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/utilities/version_check.py
"""Version checking utilities for FastMCP.""" from __future__ import annotations import json import time from pathlib import Path import httpx from packaging.version import Version from fastmcp.utilities.logging import get_logger logger = get_logger(__name__) PYPI_URL = "https://pypi.org/pypi/fastmcp/json" CACHE_...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/utilities/version_check.py", "license": "Apache License 2.0", "lines": 114, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/utilities/test_version_check.py
"""Tests for version checking utilities.""" import json import time from pathlib import Path from unittest.mock import MagicMock, patch import httpx import pytest from fastmcp.utilities.version_check import ( CACHE_TTL_SECONDS, _fetch_latest_version, _get_cache_path, _read_cache, _write_cache, ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/utilities/test_version_check.py", "license": "Apache License 2.0", "lines": 260, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/middleware/ping.py
"""Ping middleware for keeping client connections alive.""" from typing import Any import anyio from .middleware import CallNext, Middleware, MiddlewareContext class PingMiddleware(Middleware): """Middleware that sends periodic pings to keep client connections alive. Starts a background ping task on first...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/middleware/ping.py", "license": "Apache License 2.0", "lines": 54, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/server/middleware/test_ping.py
"""Tests for ping middleware.""" from unittest.mock import AsyncMock, MagicMock import anyio import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.server.middleware.ping import PingMiddleware class TestPingMiddlewareInit: """Test PingMiddleware initialization.""" def tes...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/middleware/test_ping.py", "license": "Apache License 2.0", "lines": 169, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/prompts/test_standalone_decorator.py
"""Tests for the standalone @prompt decorator. The @prompt decorator attaches metadata to functions without registering them to a server. Functions can be added explicitly via server.add_prompt() or discovered by FileSystemProvider. """ from typing import cast import pytest from fastmcp import FastMCP from fastmcp....
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/prompts/test_standalone_decorator.py", "license": "Apache License 2.0", "lines": 105, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/resources/test_standalone_decorator.py
"""Tests for the standalone @resource decorator. The @resource decorator attaches metadata to functions without registering them to a server. Functions can be added explicitly via server.add_resource() / server.add_template() or discovered by FileSystemProvider. """ from typing import cast import pytest from fastmc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/resources/test_standalone_decorator.py", "license": "Apache License 2.0", "lines": 116, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/tools/test_standalone_decorator.py
"""Tests for the standalone @tool decorator. The @tool decorator attaches metadata to functions without registering them to a server. Functions can be added explicitly via server.add_tool() or discovered by FileSystemProvider. """ from typing import cast import pytest from fastmcp import FastMCP from fastmcp.client...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/tools/test_standalone_decorator.py", "license": "Apache License 2.0", "lines": 105, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/lifespan.py
"""Composable lifespans for FastMCP servers. This module provides a `@lifespan` decorator for creating composable server lifespans that can be combined using the `|` operator. Example: ```python from fastmcp import FastMCP from fastmcp.server.lifespan import lifespan @lifespan async def db_lifesp...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/lifespan.py", "license": "Apache License 2.0", "lines": 148, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:src/fastmcp/utilities/lifespan.py
"""Lifespan utilities for combining async context manager lifespans.""" from __future__ import annotations from collections.abc import AsyncIterator, Callable, Mapping from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager from typing import Any, TypeVar AppT = TypeVar("AppT") def ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/utilities/lifespan.py", "license": "Apache License 2.0", "lines": 41, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:examples/filesystem-provider/mcp/prompts/assistant.py
"""Assistant prompts.""" from fastmcp.prompts import prompt @prompt def code_review(code: str, language: str = "python") -> str: """Generate a code review prompt. Args: code: The code to review. language: Programming language (default: python). """ return f"""Please review this {lang...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/filesystem-provider/mcp/prompts/assistant.py", "license": "Apache License 2.0", "lines": 30, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:examples/filesystem-provider/mcp/resources/config.py
"""Configuration resources - static and templated.""" import json from fastmcp.resources import resource # Static resource - no parameters in URI @resource("config://app") def get_app_config() -> str: """Get application configuration.""" return json.dumps( { "name": "FilesystemDemo", ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/filesystem-provider/mcp/resources/config.py", "license": "Apache License 2.0", "lines": 46, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/filesystem-provider/mcp/tools/calculator.py
"""Math tools with custom metadata.""" from fastmcp.tools import tool @tool( name="add-numbers", # Custom name (default would be "add") description="Add two numbers together.", tags={"math", "arithmetic"}, ) def add(a: float, b: float) -> float: """Add two numbers.""" return a + b @tool(tags={...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/filesystem-provider/mcp/tools/calculator.py", "license": "Apache License 2.0", "lines": 18, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/filesystem-provider/mcp/tools/greeting.py
"""Greeting tools - multiple tools in one file.""" from fastmcp.tools import tool @tool def greet(name: str) -> str: """Greet someone by name. Args: name: The person's name. """ return f"Hello, {name}!" @tool def farewell(name: str) -> str: """Say goodbye to someone. Args: ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/filesystem-provider/mcp/tools/greeting.py", "license": "Apache License 2.0", "lines": 19, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:examples/filesystem-provider/server.py
"""Filesystem-based MCP server using FileSystemProvider. This example demonstrates how to use FileSystemProvider to automatically discover and register tools, resources, and prompts from the filesystem. Run: fastmcp run examples/filesystem-provider/server.py Inspect: fastmcp inspect examples/filesystem-provi...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/filesystem-provider/server.py", "license": "Apache License 2.0", "lines": 21, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:tests/fs/test_discovery.py
"""Tests for filesystem discovery module.""" from pathlib import Path from fastmcp.resources.template import FunctionResourceTemplate from fastmcp.server.providers.filesystem_discovery import ( discover_and_import, discover_files, extract_components, import_module_from_file, ) from fastmcp.tools impor...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/fs/test_discovery.py", "license": "Apache License 2.0", "lines": 282, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/fs/test_provider.py
"""Tests for FileSystemProvider.""" import time from pathlib import Path from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.server.providers import FileSystemProvider class TestFileSystemProvider: """Tests for FileSystemProvider.""" def test_provider_empty_directory(self, tmp_path: ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/fs/test_provider.py", "license": "Apache License 2.0", "lines": 334, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:examples/custom_tool_serializer_decorator.py
"""Example of custom tool serialization using ToolResult and a wrapper decorator. This pattern provides explicit control over how tool outputs are serialized, making the serialization visible in each tool's code. """ import asyncio import inspect from collections.abc import Callable from functools import wraps from t...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/custom_tool_serializer_decorator.py", "license": "Apache License 2.0", "lines": 50, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/deprecated/test_tool_serializer.py
"""Tests for deprecated tool serializer functionality. These tests verify that serializer parameters still work but are deprecated. All serializer-related tests should be moved here. """ import warnings import pytest from inline_snapshot import snapshot from mcp.types import TextContent from fastmcp import FastMCP ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/deprecated/test_tool_serializer.py", "license": "Apache License 2.0", "lines": 126, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_resource_task_meta_parameter.py
""" Tests for the explicit task_meta parameter on FastMCP.read_resource(). These tests verify that the task_meta parameter provides explicit control over sync vs task execution for resources and resource templates. """ import pytest from mcp.shared.exceptions import McpError from fastmcp import FastMCP from fastmcp....
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_resource_task_meta_parameter.py", "license": "Apache License 2.0", "lines": 205, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_meta_parameter.py
""" Tests for the explicit task_meta parameter on FastMCP.call_tool(). These tests verify that the task_meta parameter provides explicit control over sync vs task execution, replacing implicit contextvar-based behavior. """ import mcp.types import pytest from fastmcp import FastMCP from fastmcp.client import Client ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_meta_parameter.py", "license": "Apache License 2.0", "lines": 229, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/test_base_provider.py
"""Tests for base Provider class behavior.""" from typing import Any from fastmcp.server.providers.base import Provider from fastmcp.server.tasks.config import TaskConfig from fastmcp.server.transforms import Namespace from fastmcp.tools.tool import Tool, ToolResult class CustomTool(Tool): """A custom Tool subc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_base_provider.py", "license": "Apache License 2.0", "lines": 61, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/utilities/async_utils.py
"""Async utilities for FastMCP.""" import asyncio import functools import inspect from collections.abc import Awaitable, Callable from typing import Any, Literal, TypeVar, overload import anyio from anyio.to_thread import run_sync as run_sync_in_threadpool T = TypeVar("T") def is_coroutine_function(fn: Any) -> boo...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/utilities/async_utils.py", "license": "Apache License 2.0", "lines": 62, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/deprecated/server/test_include_exclude_tags.py
"""Tests for removed include_tags/exclude_tags parameters.""" import pytest from fastmcp import FastMCP class TestIncludeExcludeTagsRemoved: """Test that include_tags/exclude_tags raise TypeError with migration hints.""" def test_exclude_tags_raises_type_error(self): with pytest.raises(TypeError, m...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/deprecated/server/test_include_exclude_tags.py", "license": "Apache License 2.0", "lines": 17, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/test_local_provider.py
"""Comprehensive tests for LocalProvider. Tests cover: - Storage operations (add/remove tools, resources, templates, prompts) - Provider interface (list/get operations) - Decorator patterns (all calling styles) - Tool transformations - Standalone usage (provider attached to multiple servers) - Task registration """ f...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_local_provider.py", "license": "Apache License 2.0", "lines": 623, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/test_local_provider_prompts.py
"""Tests for prompt behavior in LocalProvider. Tests cover: - Prompt context injection - Prompt decorator patterns """ import pytest from mcp.types import TextContent from fastmcp import Client, Context, FastMCP from fastmcp.prompts.prompt import Prompt, PromptResult class TestPromptContext: async def test_pro...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_local_provider_prompts.py", "license": "Apache License 2.0", "lines": 363, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/test_local_provider_resources.py
"""Tests for resource and template behavior in LocalProvider. Tests cover: - Resource context injection - Resource templates and URI parsing - Resource template context injection - Resource decorator patterns - Template decorator patterns """ import pytest from mcp.types import TextResourceContents from pydantic impo...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_local_provider_resources.py", "license": "Apache License 2.0", "lines": 725, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/providers/openapi/components.py
"""OpenAPI component classes: Tool, Resource, and ResourceTemplate.""" from __future__ import annotations import json import re import warnings from collections.abc import Callable from typing import TYPE_CHECKING, Any import httpx from mcp.types import ToolAnnotations from pydantic.networks import AnyUrl import fa...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/providers/openapi/components.py", "license": "Apache License 2.0", "lines": 350, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/providers/openapi/provider.py
"""OpenAPIProvider for creating MCP components from OpenAPI specifications.""" from __future__ import annotations from collections import Counter from collections.abc import AsyncIterator, Sequence from contextlib import asynccontextmanager from typing import Any, Literal, cast import httpx from jsonschema_path impo...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/providers/openapi/provider.py", "license": "Apache License 2.0", "lines": 373, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/providers/openapi/routing.py
"""Route mapping logic for OpenAPI operations.""" from __future__ import annotations import enum import re from collections.abc import Callable from dataclasses import dataclass, field from re import Pattern from typing import TYPE_CHECKING, Literal if TYPE_CHECKING: from fastmcp.server.providers.openapi.compone...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/providers/openapi/routing.py", "license": "Apache License 2.0", "lines": 87, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/deprecated/openapi/test_openapi.py
"""Tests for deprecated OpenAPI imports. These tests verify that the old import paths still work and emit deprecation warnings, ensuring backwards compatibility. """ import warnings import httpx class TestDeprecatedServerOpenAPIImports: """Test deprecated imports from fastmcp.server.openapi.""" def test_i...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/deprecated/openapi/test_openapi.py", "license": "Apache License 2.0", "lines": 130, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/openapi/test_end_to_end_compatibility.py
"""End-to-end tests for OpenAPIProvider implementation.""" import httpx import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.server.providers.openapi import OpenAPIProvider def create_openapi_server( openapi_spec: dict, client, name: str = "OpenAPI Server", ) -> FastM...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/openapi/test_end_to_end_compatibility.py", "license": "Apache License 2.0", "lines": 186, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/providers/proxy.py
"""ProxyProvider for proxying to remote MCP servers. This module provides the `ProxyProvider` class that proxies components from a remote MCP server via a client factory. It also provides proxy component classes that forward execution to remote servers. """ from __future__ import annotations import base64 import ins...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/providers/proxy.py", "license": "Apache License 2.0", "lines": 817, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/tasks/routing.py
"""Task routing helper for MCP components. Provides unified task mode enforcement and docket routing logic. """ from __future__ import annotations from typing import TYPE_CHECKING, Any, Literal import mcp.types from mcp.shared.exceptions import McpError from mcp.types import METHOD_NOT_FOUND, ErrorData from fastmc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/routing.py", "license": "Apache License 2.0", "lines": 59, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/server/tasks/test_custom_subclass_tasks.py
"""Tests for custom component subclasses with task support. Verifies that custom Tool, Resource, and Prompt subclasses can use background task execution by setting task_config. """ import asyncio from typing import Any from unittest.mock import MagicMock import pytest from fastmcp import FastMCP from fastmcp.client...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_custom_subclass_tasks.py", "license": "Apache License 2.0", "lines": 131, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/providers/fastmcp_provider.py
"""FastMCPProvider for wrapping FastMCP servers as providers. This module provides the `FastMCPProvider` class that wraps a FastMCP server and exposes its components through the Provider interface. It also provides FastMCPProvider* component classes that delegate execution to the wrapped server's middleware, ensuring...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/providers/fastmcp_provider.py", "license": "Apache License 2.0", "lines": 579, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/server/providers/test_fastmcp_provider.py
"""Tests for FastMCPProvider.""" import mcp.types as mt from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.prompts.prompt import PromptResult from fastmcp.resources.resource import ResourceResult from fastmcp.server.middleware import CallNext, Middleware, MiddlewareContext from fastmcp.server....
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_fastmcp_provider.py", "license": "Apache License 2.0", "lines": 331, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/providers/test_transforming_provider.py
"""Tests for Namespace and ToolTransform.""" import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.server.providers import FastMCPProvider from fastmcp.server.transforms import Namespace, ToolTransform from fastmcp.tools.tool_transform import ToolTransformConfig class TestNamespac...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/providers/test_transforming_provider.py", "license": "Apache License 2.0", "lines": 214, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:examples/providers/sqlite/server.py
# /// script # dependencies = ["aiosqlite", "fastmcp"] # /// """ MCP server with database-configured tools. Tools are loaded from tools.db on each request, so you can add/modify/disable tools in the database without restarting the server. Run with: uv run fastmcp run examples/providers/sqlite/server.py """ from __fu...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/providers/sqlite/server.py", "license": "Apache License 2.0", "lines": 106, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:examples/providers/sqlite/setup_db.py
# /// script # dependencies = ["aiosqlite"] # /// """ Creates and seeds the tools database. Run with: uv run examples/providers/sqlite/setup_db.py """ import asyncio import json from pathlib import Path import aiosqlite DB_PATH = Path(__file__).parent / "tools.db" async def setup_database() -> None: """Create...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/providers/sqlite/setup_db.py", "license": "Apache License 2.0", "lines": 91, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/server/test_providers.py
"""Tests for providers.""" from collections.abc import Sequence from typing import Any import pytest from mcp.types import AnyUrl, TextContent from fastmcp import FastMCP from fastmcp.prompts.function_prompt import FunctionPrompt from fastmcp.prompts.prompt import Prompt from fastmcp.resources.function_resource impo...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/test_providers.py", "license": "Apache License 2.0", "lines": 360, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:examples/sampling/server_fallback.py
# /// script # dependencies = ["anthropic", "fastmcp", "rich"] # /// """ Server-Side Fallback Handler Demonstrates configuring a sampling handler on the server. This ensures sampling works even when the client doesn't provide a handler. The server runs as an HTTP server that can be connected to by any MCP client. Ru...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/sampling/server_fallback.py", "license": "Apache License 2.0", "lines": 65, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/sampling/structured_output.py
# /// script # dependencies = ["anthropic", "fastmcp", "rich"] # /// """ Structured Output Sampling Demonstrates using `result_type` to get validated Pydantic models from an LLM. The server exposes a sentiment analysis tool that returns structured data. Run: uv run examples/sampling/structured_output.py """ impo...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/sampling/structured_output.py", "license": "Apache License 2.0", "lines": 83, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/sampling/text.py
# /// script # dependencies = ["anthropic", "fastmcp", "rich"] # /// """ Simple Text Sampling Demonstrates the basic MCP sampling flow where a server tool requests an LLM completion from the client. Run: uv run examples/sampling/text.py """ import asyncio from rich.console import Console from rich.panel import ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/sampling/text.py", "license": "Apache License 2.0", "lines": 56, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/sampling/tool_use.py
# /// script # dependencies = ["anthropic", "fastmcp", "rich"] # /// """ Sampling with Tools Demonstrates giving an LLM tools to use during sampling. The LLM can call helper functions to gather information before responding. Run: uv run examples/sampling/tool_use.py """ import asyncio import random from datetime...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/sampling/tool_use.py", "license": "Apache License 2.0", "lines": 92, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:src/fastmcp/client/sampling/handlers/anthropic.py
"""Anthropic sampling handler for FastMCP.""" from collections.abc import Iterator, Sequence from typing import Any from mcp.types import CreateMessageRequestParams as SamplingParams from mcp.types import ( CreateMessageResult, CreateMessageResultWithTools, ModelPreferences, SamplingMessage, Sampl...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/client/sampling/handlers/anthropic.py", "license": "Apache License 2.0", "lines": 338, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/client/sampling/handlers/test_anthropic_handler.py
from unittest.mock import MagicMock import pytest from anthropic import AsyncAnthropic from anthropic.types import Message, TextBlock, ToolUseBlock, Usage from mcp.types import ( CreateMessageResult, CreateMessageResultWithTools, ModelHint, ModelPreferences, SamplingMessage, TextContent, To...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/sampling/handlers/test_anthropic_handler.py", "license": "Apache License 2.0", "lines": 209, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/client/sampling/handlers/openai.py
"""OpenAI sampling handler for FastMCP.""" import json from collections.abc import Iterator, Sequence from typing import Any, get_args from mcp import ClientSession, ServerSession from mcp.shared.context import LifespanContextT, RequestContext from mcp.types import CreateMessageRequestParams as SamplingParams from mc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/client/sampling/handlers/openai.py", "license": "Apache License 2.0", "lines": 358, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/sampling/run.py
"""Sampling types and helper functions for FastMCP servers.""" from __future__ import annotations import inspect import json from collections.abc import Callable, Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Generic, Literal, cast import anyio from mcp.types import ( ClientCa...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/sampling/run.py", "license": "Apache License 2.0", "lines": 602, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/sampling/sampling_tool.py
"""SamplingTool for use during LLM sampling requests.""" from __future__ import annotations import inspect from collections.abc import Callable from typing import Any from mcp.types import TextContent from mcp.types import Tool as SDKTool from pydantic import ConfigDict from fastmcp.tools.function_parsing import Pa...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/sampling/sampling_tool.py", "license": "Apache License 2.0", "lines": 149, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/server/sampling/test_sampling_tool.py
"""Tests for SamplingTool.""" import pytest from fastmcp.server.sampling import SamplingTool from fastmcp.tools.function_tool import FunctionTool from fastmcp.tools.tool_transform import ArgTransform, TransformedTool class TestSamplingToolFromFunction: """Tests for SamplingTool.from_function().""" def test...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/sampling/test_sampling_tool.py", "license": "Apache License 2.0", "lines": 216, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/tasks/capabilities.py
"""SEP-1686 task capabilities declaration.""" from importlib.util import find_spec from mcp.types import ( ServerTasksCapability, ServerTasksRequestsCapability, TasksCallCapability, TasksCancelCapability, TasksListCapability, TasksToolsCapability, ) def _is_docket_available() -> bool: ""...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/capabilities.py", "license": "Apache License 2.0", "lines": 32, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:src/fastmcp/server/event_store.py
"""EventStore implementation backed by AsyncKeyValue. This module provides an EventStore implementation that enables SSE polling/resumability for Streamable HTTP transports. Events are stored using the key_value package's AsyncKeyValue protocol, allowing users to configure any compatible backend (in-memory, Redis, etc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/event_store.py", "license": "Apache License 2.0", "lines": 139, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/server/test_event_store.py
"""Tests for the EventStore implementation.""" import pytest from mcp.server.streamable_http import EventMessage from mcp.types import JSONRPCMessage, JSONRPCRequest from fastmcp.server.event_store import EventEntry, EventStore, StreamEventList class TestEventEntry: def test_event_entry_with_message(self): ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/test_event_store.py", "license": "Apache License 2.0", "lines": 181, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_mount.py
""" Tests for MCP SEP-1686 task protocol support through mounted servers. Verifies that tasks work seamlessly when calling tools/prompts/resources on mounted child servers through a parent server. """ import asyncio import mcp.types as mt import pytest from docket import Docket from fastmcp import FastMCP from fast...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_mount.py", "license": "Apache License 2.0", "lines": 735, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_proxy.py
""" Tests for MCP SEP-1686 task protocol behavior through proxy servers. Proxy servers explicitly forbid task-augmented execution. All proxy components (tools, prompts, resources) have task_config.mode="forbidden". Clients connecting through proxies can: - Execute tools/prompts/resources normally (sync execution) - N...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_proxy.py", "license": "Apache License 2.0", "lines": 126, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:src/fastmcp/server/tasks/config.py
"""TaskConfig for MCP SEP-1686 background task execution modes. This module defines the configuration for how tools, resources, and prompts handle task-augmented execution as specified in SEP-1686. """ from __future__ import annotations import functools import inspect from collections.abc import Callable from datacl...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/config.py", "license": "Apache License 2.0", "lines": 111, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:examples/tasks/client.py
""" FastMCP Tasks Example Client Demonstrates calling tools both immediately and as background tasks, with real-time progress updates via status callbacks. Usage: # Make sure environment is configured (source .envrc or use direnv) source .envrc # Background task execution with progress callbacks (default...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/tasks/client.py", "license": "Apache License 2.0", "lines": 118, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:examples/tasks/server.py
""" FastMCP Tasks Example Server Demonstrates background task execution with progress tracking using Docket. Setup: 1. Start Redis: docker compose up -d 2. Load environment: source .envrc 3. Run server: fastmcp run server.py The example uses Redis by default to demonstrate distributed task execution and ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/tasks/server.py", "license": "Apache License 2.0", "lines": 56, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:src/fastmcp/cli/tasks.py
"""FastMCP tasks CLI for Docket task management.""" import asyncio import sys from typing import Annotated import cyclopts from rich.console import Console from fastmcp.utilities.cli import load_and_merge_config from fastmcp.utilities.logging import get_logger logger = get_logger("cli.tasks") console = Console() t...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/cli/tasks.py", "license": "Apache License 2.0", "lines": 89, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/client/tasks.py
"""SEP-1686 client Task classes.""" from __future__ import annotations import abc import asyncio import inspect import time import weakref from collections.abc import Awaitable, Callable from datetime import datetime, timezone from typing import TYPE_CHECKING, Generic, TypeVar import mcp.types from mcp.types import ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/client/tasks.py", "license": "Apache License 2.0", "lines": 446, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/dependencies.py
"""Dependency injection exports for FastMCP. This module re-exports dependency injection symbols to provide a clean, centralized import location for all dependency-related functionality. DI features (Depends, CurrentContext, CurrentFastMCP) work without pydocket using the uncalled-for DI engine. Only task-related dep...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/dependencies.py", "license": "Apache License 2.0", "lines": 35, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:src/fastmcp/server/tasks/handlers.py
"""SEP-1686 task execution handlers. Handles queuing tool/prompt/resource executions to Docket as background tasks. """ from __future__ import annotations import uuid from contextlib import suppress from datetime import datetime, timezone from typing import TYPE_CHECKING, Any, Literal import mcp.types from mcp.shar...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/handlers.py", "license": "Apache License 2.0", "lines": 191, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:src/fastmcp/server/tasks/keys.py
"""Task key management for SEP-1686 background tasks. Task keys encode security scoping and metadata in the Docket key format: `{session_id}:{client_task_id}:{task_type}:{component_identifier}` This format provides: - Session-based security scoping (prevents cross-session access) - Task type identification (tool/...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/keys.py", "license": "Apache License 2.0", "lines": 68, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
PrefectHQ/fastmcp:src/fastmcp/server/tasks/subscriptions.py
"""Task subscription helpers for sending MCP notifications (SEP-1686). Subscribes to Docket execution state changes and sends notifications/tasks/status to clients when their tasks change state. This module requires fastmcp[tasks] (pydocket). It is only imported when docket is available. """ from __future__ import a...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/tasks/subscriptions.py", "license": "Apache License 2.0", "lines": 176, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:tests/cli/test_tasks.py
"""Tests for the fastmcp tasks CLI.""" import pytest from fastmcp.cli.tasks import check_distributed_backend, tasks_app from fastmcp.utilities.tests import temporary_settings class TestCheckDistributedBackend: """Test the distributed backend checker function.""" def test_succeeds_with_redis_url(self): ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/cli/test_tasks.py", "license": "Apache License 2.0", "lines": 37, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_client_prompt_tasks.py
""" Tests for client-side prompt task methods. Tests the client's get_prompt_as_task method. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import PromptTask @pytest.fixture async def prompt_server(): """Create a test server with background-enabled pro...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_client_prompt_tasks.py", "license": "Apache License 2.0", "lines": 75, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_client_resource_tasks.py
""" Tests for client-side resource task methods. Tests the client's read_resource_as_task method. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import ResourceTask @pytest.fixture async def resource_server(): """Create a test server with background-en...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_client_resource_tasks.py", "license": "Apache License 2.0", "lines": 76, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_client_task_notifications.py
""" Tests for client-side handling of notifications/tasks/status (SEP-1686 lines 436-444). Verifies that Task objects receive notifications, update their cache, wake up wait() calls, and invoke user callbacks. """ import asyncio import time import pytest from mcp.types import GetTaskResult from fastmcp import FastM...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_client_task_notifications.py", "license": "Apache License 2.0", "lines": 148, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_client_task_protocol.py
""" Tests for client-side task protocol. Generic protocol tests that use tools as test fixtures. """ import asyncio from fastmcp import FastMCP from fastmcp.client import Client async def test_end_to_end_task_flow(): """Complete end-to-end flow: submit, poll, retrieve.""" start_signal = asyncio.Event() ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_client_task_protocol.py", "license": "Apache License 2.0", "lines": 63, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_client_tool_tasks.py
""" Tests for client-side tool task methods. Tests the client's tool-specific task functionality, parallel to test_client_prompt_tasks.py and test_client_resource_tasks.py. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import ToolTask @pytest.fixture asyn...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_client_tool_tasks.py", "license": "Apache License 2.0", "lines": 63, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_task_context_validation.py
""" Tests for Task client context validation. Verifies that Task methods properly validate client context and that cached results remain accessible outside context. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def task_server(): """Create a test server w...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_task_context_validation.py", "license": "Apache License 2.0", "lines": 159, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/client/tasks/test_task_result_caching.py
""" Tests for Task result caching behavior. Verifies that Task.result() and await task cache results properly to avoid redundant server calls and ensure consistent object identity. """ from fastmcp import FastMCP from fastmcp.client import Client async def test_tool_task_result_cached_on_first_call(): """First ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/client/tasks/test_task_result_caching.py", "license": "Apache License 2.0", "lines": 231, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_progress_dependency.py
"""Tests for FastMCP Progress dependency.""" from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.dependencies import Progress async def test_progress_in_immediate_execution(): """Test Progress dependency when calling tool immediately with Docket enabled.""" mcp = FastMCP("test") @...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_progress_dependency.py", "license": "Apache License 2.0", "lines": 116, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_server_tasks_parameter.py
""" Tests for server `tasks` parameter default inheritance. Verifies that the server's `tasks` parameter correctly sets defaults for all components (tools, prompts, resources), and that explicit component-level settings properly override the server default. """ from fastmcp import FastMCP from fastmcp.client import C...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_server_tasks_parameter.py", "license": "Apache License 2.0", "lines": 295, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_sync_function_task_disabled.py
""" Tests that synchronous functions cannot be used as background tasks. Docket requires async functions for background execution. FastMCP raises ValueError when task=True is used with a sync function. """ import pytest from fastmcp import FastMCP from fastmcp.prompts.function_prompt import FunctionPrompt from fastm...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_sync_function_task_disabled.py", "license": "Apache License 2.0", "lines": 164, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_capabilities.py
""" Tests for SEP-1686 task capabilities declaration. Verifies that the server correctly advertises task support. Task protocol is now always enabled. """ from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.server.tasks import get_task_capabilities async def test_capabilities_include_tasks():...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_capabilities.py", "license": "Apache License 2.0", "lines": 33, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_dependencies.py
"""Tests for dependency injection in background tasks. These tests verify that Docket's dependency system works correctly when user functions are queued as background tasks. Dependencies like CurrentDocket(), CurrentFastMCP(), and Depends() should be resolved in the worker context. """ from contextlib import asynccon...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_dependencies.py", "license": "Apache License 2.0", "lines": 201, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_metadata.py
""" Tests for SEP-1686 related-task metadata in protocol responses. Per the spec, all task-related responses MUST include io.modelcontextprotocol/related-task in _meta. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def metadata_server(): """Create a serve...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_metadata.py", "license": "Apache License 2.0", "lines": 46, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_methods.py
""" Tests for task protocol methods. Tests the tasks/get, tasks/result, and tasks/list JSON-RPC protocol methods. """ import asyncio import pytest from mcp.shared.exceptions import McpError from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def endpoint_server(): """Create a s...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_methods.py", "license": "Apache License 2.0", "lines": 161, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_prompts.py
""" Tests for SEP-1686 background task support for prompts. Tests that prompts with task=True can execute in background. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import PromptTask @pytest.fixture async def prompt_server(): """Create a FastMCP ser...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_prompts.py", "license": "Apache License 2.0", "lines": 67, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_protocol.py
""" Tests for SEP-1686 protocol-level task handling. Generic protocol tests that use tools as test fixtures. Tests metadata, notifications, and error handling at the protocol level. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def task_enabled_server(): ...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_protocol.py", "license": "Apache License 2.0", "lines": 60, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_resources.py
""" Tests for SEP-1686 background task support for resources. Tests that resources with task=True can execute in background. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import ResourceTask @pytest.fixture async def resource_server(): """Create a Fas...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_resources.py", "license": "Apache License 2.0", "lines": 79, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_return_types.py
""" Tests to verify all return types work identically with task=True. These tests ensure that enabling background task support doesn't break existing functionality - any tool/prompt/resource should work exactly the same whether task=True or task=False. """ from dataclasses import dataclass from datetime import dateti...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_return_types.py", "license": "Apache License 2.0", "lines": 540, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_security.py
""" Tests for session-based task ID isolation (CRITICAL SECURITY). Ensures that tasks are properly scoped to sessions and clients cannot access each other's tasks. """ import pytest from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def task_server(): """Create a server with ba...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_security.py", "license": "Apache License 2.0", "lines": 35, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_status_notifications.py
""" Tests for notifications/tasks/status subscription mechanism (SEP-1686 lines 436-444). Per the spec, servers MAY send notifications/tasks/status when task state changes. This is an optional optimization that reduces client polling frequency. These tests verify that the subscription mechanism works correctly withou...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_status_notifications.py", "license": "Apache License 2.0", "lines": 119, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_tools.py
""" Tests for server-side tool task behavior. Tests tool-specific task handling, parallel to test_task_prompts.py and test_task_resources.py. """ import asyncio import pytest from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.client.tasks import ToolTask @pytest.fixture async def tool_serv...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_tools.py", "license": "Apache License 2.0", "lines": 75, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/tasks/test_task_ttl.py
""" Tests for SEP-1686 ttl parameter handling. Per the spec, servers MUST return ttl in all tasks/get responses, and results should be retained for ttl milliseconds after completion. """ import asyncio import pytest from fastmcp import FastMCP from fastmcp.client import Client @pytest.fixture async def keepalive_...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/tasks/test_task_ttl.py", "license": "Apache License 2.0", "lines": 67, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/test_dependencies.py
"""Tests for Docket-style dependency injection in FastMCP.""" from contextlib import asynccontextmanager, contextmanager import mcp.types as mcp_types import pytest from mcp.types import TextContent, TextResourceContents from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.dependencies import C...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/test_dependencies.py", "license": "Apache License 2.0", "lines": 811, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/server/test_server_docket.py
"""Tests for Docket integration in FastMCP.""" import asyncio from contextlib import asynccontextmanager from docket import Docket from docket.worker import Worker from fastmcp import FastMCP from fastmcp.client import Client from fastmcp.dependencies import CurrentDocket, CurrentWorker from fastmcp.server.dependenc...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/server/test_server_docket.py", "license": "Apache License 2.0", "lines": 170, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:examples/auth/mounted/client.py
"""Mounted OAuth servers client example for FastMCP. This example demonstrates connecting to multiple mounted OAuth-protected MCP servers. To run: python client.py """ import asyncio from fastmcp.client import Client GITHUB_URL = "http://127.0.0.1:8000/api/mcp/github/mcp" GOOGLE_URL = "http://127.0.0.1:8000/ap...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/auth/mounted/client.py", "license": "Apache License 2.0", "lines": 38, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
PrefectHQ/fastmcp:examples/auth/mounted/server.py
"""Mounted OAuth servers example for FastMCP. This example demonstrates mounting multiple OAuth-protected MCP servers in a single application, each with its own provider. It showcases RFC 8414 path-aware discovery where each server has its own authorization server metadata endpoint. URL structure: - GitHub MCP: http:...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/auth/mounted/server.py", "license": "Apache License 2.0", "lines": 95, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:tests/deprecated/test_openapi_deprecations.py
"""Tests for OpenAPI-related deprecations in 2.14.""" import importlib import warnings import pytest pytestmark = pytest.mark.filterwarnings("default::DeprecationWarning") class TestExperimentalOpenAPIImportDeprecation: """Test experimental OpenAPI import path deprecations.""" def test_experimental_server...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/deprecated/test_openapi_deprecations.py", "license": "Apache License 2.0", "lines": 41, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:tests/utilities/openapi/test_legacy_compatibility.py
"""Tests to ensure OpenAPI schema generation works correctly.""" import pytest from fastmcp.utilities.openapi.models import ( HTTPRoute, ParameterInfo, RequestBodyInfo, ) from fastmcp.utilities.openapi.schemas import ( _combine_schemas_and_map_params, ) class TestSchemaGeneration: """Test that O...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "tests/utilities/openapi/test_legacy_compatibility.py", "license": "Apache License 2.0", "lines": 163, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
PrefectHQ/fastmcp:examples/auth/discord_oauth/client.py
"""Discord OAuth client example for connecting to FastMCP servers. This example demonstrates how to connect to a Discord OAuth-protected FastMCP server. To run: python client.py """ import asyncio from fastmcp.client import Client SERVER_URL = "http://127.0.0.1:8000/mcp" async def main(): try: as...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/auth/discord_oauth/client.py", "license": "Apache License 2.0", "lines": 22, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:examples/auth/discord_oauth/server.py
"""Discord OAuth server example for FastMCP. This example demonstrates how to protect a FastMCP server with Discord OAuth. Required environment variables: - FASTMCP_SERVER_AUTH_DISCORD_CLIENT_ID: Your Discord OAuth app client ID - FASTMCP_SERVER_AUTH_DISCORD_CLIENT_SECRET: Your Discord OAuth app client secret To run...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "examples/auth/discord_oauth/server.py", "license": "Apache License 2.0", "lines": 24, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
PrefectHQ/fastmcp:src/fastmcp/server/auth/providers/discord.py
"""Discord OAuth provider for FastMCP. This module provides a complete Discord OAuth integration that's ready to use with just a client ID and client secret. It handles all the complexity of Discord's OAuth flow, token validation, and user management. Example: ```python from fastmcp import FastMCP from fa...
{ "repo_id": "PrefectHQ/fastmcp", "file_path": "src/fastmcp/server/auth/providers/discord.py", "license": "Apache License 2.0", "lines": 240, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex