Commit graph

82 commits

Author SHA1 Message Date
Jeremiah Lowin
c397e68d39
Update ty ignore comments for 0.0.25 compatibility (#3614) 2026-03-24 20:26:26 -04:00
Marcus Shu
2d7bc4e73d
Add encoding parameter to FileResource (#3580)
* feat: Add encoding parameter to FileResource

- Add optional encoding field (str | None, default None) to FileResource.
- Pass encoding through to read_text() for cross-platform text file reading.
- Preserve backward compatibility by defaulting to system encoding.

* test: Add tests for FileResource encoding parameter

- Test UTF-8 reading with explicit encoding for non-ASCII content.
- Test backward compatibility when no encoding is specified.
- Test that encoding is ignored for binary file reads.
- Test Latin-1 reading with matching encoding.

* docs: Document FileResource encoding parameter

- Add encoding="utf-8" to FileResource example in resource classes guide.
- Update FileResource description to mention encoding support.

* feat: Change FileResource encoding default from None to utf-8

- Default to utf-8 instead of system encoding to prevent cross-platform footgun.
- Update field description to reflect new default.
- Update test to verify default encoding is utf-8 with non-ASCII content.
- Remove redundant encoding="utf-8" from docs example since it is now the default.
2026-03-22 09:55:16 -04:00
Jeremiah Lowin
360c9c31e5
fix: resolve Pyright "Module is not callable" on @tool, @resource, @prompt decorators (#3540)
* pin pydantic-monty to 0.0.8

* rename tool/prompt/resource base modules to avoid decorator name shadow

* add sys.modules shims for old submodule import paths

* preserve original module paths in deprecation warnings

* clarify when sys.modules shims can be removed
2026-03-17 18:11:42 -04:00
Jeremiah Lowin
5ff64ce21b
fix: handle re.error from malformed URI templates in build_regex (#3501) 2026-03-14 16:34:06 -04:00
Jeremiah Lowin
9ccaef2b6a
Raise ValueError for invalid boolean query params in resource templates (#3424) (#3434) 2026-03-07 11:40:29 -05:00
Jeremiah Lowin
610551c7b6
Split large test files to comply with loq line limit (#3328) 2026-02-28 11:21:11 -05:00
Bill Easton
b2f5551d22
Fix Field() handling in prompts (#3050)
Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
2026-02-01 21:28:44 -05:00
Jeremiah Lowin
8c471a499d
Run sync tools/resources/prompts in threadpool automatically (#2865) 2026-01-13 11:03:05 -05:00
Jeremiah Lowin
2b6a0faf1c
Add loq file size limits and clean up type ignores (#2859) 2026-01-13 07:29:12 -05:00
Jeremiah Lowin
1b723f302d
Decorators return functions instead of component objects (#2856) 2026-01-12 21:58:07 -05:00
Jeremiah Lowin
daa2dace2f
Add standalone decorators and eliminate fastmcp.fs module (#2832) 2026-01-10 12:16:35 -05:00
Jeremiah Lowin
fc19f1f8de
Add task_meta parameter to read_resource() for explicit task control (#2750) 2025-12-26 12:59:01 -05:00
Jeremiah Lowin
648684d2bb
Introduce ResourceResult as canonical resource return type (#2734) 2025-12-25 21:21:55 -05:00
Jeremiah Lowin
f36b147f60
Unify component storage in LocalProvider (#2680) 2025-12-23 19:24:09 -05:00
Jeremiah Lowin
d6654a2379
Add supports_tasks() method to replace string mode checks (#2664)
* Add supports_tasks() method to replace string mode checks

Consolidates task config mode checks into a readable method on TaskConfig.
Instead of `task_config.mode == "forbidden"` or `task_config.mode != "forbidden"`,
code now uses `task_config.supports_tasks()` for clearer intent.

Updated 20 instances across the codebase and added type assertions in tests
to resolve type checker warnings.

* Update test to match new error message
2025-12-21 15:41:46 -05:00
Jeremiah Lowin
caeaa86394
Simplify .key as computed property (#2648)
* Simplify .key as computed property

Keep .key as the standard lookup interface for all components but
implement it as a computed property instead of a stored field.

- Remove _key private attribute and custom model_copy(key=...)
- .key returns .name for tools/prompts, str(.uri) for resources,
  .uri_template for templates
- Use .key universally for component lookups in managers
- MountedProvider: prefix URIs only for resources/templates, not names
- Docket registration: tools/prompts use .key, resources use .name
  (matches fn.__name__ for function lookup)

* Simplify .key as computed property

Keep .key as the standard lookup interface for all components but
implement it as a computed property instead of a stored field.

- Remove _key private attribute and custom model_copy(key=...)
- .key returns .name for tools/prompts, str(.uri) for resources,
  .uri_template for templates
- Use .key universally for component lookups and Docket registration
- MountedProvider: prefix URIs only for resources/templates, not names
- Add _backend_* fields to proxy classes to preserve original identifiers
  for backend calls when prefixed via import_server

* Standardize .key as computed property

- .key is now a read-only computed property:
  - Tools/Prompts: returns .name
  - Resources: returns str(.uri)
  - Templates: returns .uri_template
- Prefixing uses model_copy(update={...}) to change underlying field
- Resource/template names are NOT prefixed, only URIs
- Move import_server tests to tests/deprecated/
2025-12-18 14:48:47 -05:00
Jeremiah Lowin
5f3bb05f99
Revert "Revert "Refactor resource behavior and add meta support (#2598)" (#2609)" (#2611)
This reverts commit 1efc4bc3ff.
2025-12-14 21:36:40 -05:00
Jeremiah Lowin
1efc4bc3ff
Revert "Refactor resource behavior and add meta support (#2598)" (#2609)
This reverts commit 12f2422e18.
2025-12-13 15:02:18 -05:00
Jeremiah Lowin
12f2422e18
Refactor resource behavior and add meta support (#2598)
* feat: make ResourceContent the canonical internal type for resources

Add Resource._read() private method that always returns ResourceContent,
maintaining backwards compatibility for custom resources returning str/bytes
from read(). Includes deprecation warning when str/bytes is returned.

* fix: address review feedback for ResourceContent

- Remove ResourceContent from root exports (import from fastmcp.resources)
- Fix FunctionResource.read() return type to str | bytes | ResourceContent
- Decode base64 blobs in proxy when receiving from remote servers
- Preserve meta in ProxyResource cached content

* fix: add empty result guards in proxy resource reads
2025-12-13 11:45:38 -05:00
Jeremiah Lowin
0cf12fa30c
Add regression tests for functools.wraps + Context (#2524) (#2566)
Follow-up to PR #2563 which fixed the signature handling in
create_function_without_params. These tests ensure the fix
works end-to-end for all object types that support Context injection.
2025-12-06 12:32:39 -05:00
Jeremiah Lowin
07750efaab
Fix type errors for ty 0.0.1-alpha.31 upgrade (#2561)
* Fix type errors for ty 0.0.1-alpha.31 upgrade

Add type ignores and fixes for ty's stricter checking:
- Path(None) guards in cli.py
- isinstance checks for ElicitRequestFormParams (URL elicitation support)
- TODO(ty) comments for match/isinstance narrowing bugs
- Method override type ignores for generic covariance
- Starlette Middleware typing workarounds
- Dynamic type construction ignores in json_schema_type.py

* Fix remaining type errors for ty 0.0.1-alpha.31

- Add asserts for optional attribute access in tests
- Add type ignores for dynamic httpx transport internals
- Add TODO(ty) comments for `in` operator on str|bytes
- Add TODO(ty) comments for Starlette Middleware typing
- Use cast for prompt.fn async validation in server.py

* Upgrade ty to 0.0.1-alpha.31

Fixes additional test file type errors discovered after upgrade.
2025-12-05 21:29:14 -05:00
Josh Thomas
08c49e62e8
Fix query-only resource templates not matching URIs without query strings (#2323)
* Fix query-only resource templates not matching URIs without query strings

* apply the same fix to `has_resource`
2025-11-01 11:27:37 -04:00
Jeremiah Lowin
20c6749de9
Allow direct instantiation of Prompt and Resource classes (#2031) 2025-10-08 21:06:41 -04:00
Jeremiah Lowin
35a8c32f61
Add RFC 6570 query parameter support to resource templates (#1971) 2025-09-30 16:28:09 -04:00
William Easton
fe4f31c2c7
Enable more type checking rules (#1775) 2025-09-07 11:11:44 -04:00
Jeremiah Lowin
19a4dd85d4
Ensure resource + template names are properly prefixed when importing/mounting (#1423) 2025-08-08 21:29:07 -04:00
Jeremiah Lowin
3fc2510110
Add meta parameter support to tools, resources, templates, and prompts decorators (#1294) 2025-07-29 17:16:05 -04:00
Jeremiah Lowin
0600834da4 Fix single-element list unwrapping in tool content
Single-element lists like [1] were being incorrectly unwrapped to "1"
in unstructured content while multi-element lists remained as lists.
This created inconsistent behavior where the structure was lost for
single items.

This fix ensures lists always preserve their structure in unstructured
content regardless of length, making behavior consistent and predictable.

Also removes pretty-printing from JSON serialization for more compact
output across tools, prompts, and resources.

Fixes #1064

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-07 12:07:16 -04:00
Jeremiah Lowin
228425e309
Avoid propagating logs (#1042)
* Avoid propagating logs

* Set up caplog for non-root loggers

* Update tests
2025-07-04 12:22:11 -04:00
Jeremiah Lowin
38036b1f42 Add automatic MCP list change notifications and client message handling
Implements comprehensive notification system for tools, resources, and prompts with automatic client updates and flexible message handlers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-24 22:33:06 -04:00
Jeremiah Lowin
085c5b765b Update docs and tests 2025-06-19 17:06:54 -04:00
Jeremiah Lowin
2e31b2704b Update tests 2025-06-19 14:05:19 -04:00
Jeremiah Lowin
35e13ef9bf Update resource manager 2025-06-19 12:22:14 -04:00
Jeremiah Lowin
ad45f0572a Merge branch 'main' into include-exclude 2025-06-10 19:31:25 -04:00
Jeremiah Lowin
3095ce5e57 Fix field validator for resource 2025-06-10 09:43:48 -04:00
Jeremiah Lowin
956488635e Add support for tag-based include/exclude 2025-06-07 18:38:29 -04:00
Jeremiah Lowin
6b308a6651 Formalize template/functiontemplate 2025-06-04 11:29:59 -04:00
Jeremiah Lowin
3a0faf5fcf Formalize resource/functionresource replationship 2025-06-04 11:06:59 -04:00
Jeremiah Lowin
f1e3713fc6 Update test typing 2025-05-31 20:41:18 -04:00
Jeremiah Lowin
010170337f Ensure that tools/templates/prompts are compatible with callable objects 2025-05-23 18:53:55 -04:00
Jeremiah Lowin
53b067b4e7 Make error masking configurable 2025-05-22 09:08:16 -04:00
Amerr, Ziad (ext) (DI SW ICS MNA RD QA QST 2)
4561d722ad Removed trailing whitespace 2025-05-19 20:14:59 +03:00
Amerr, Ziad (ext) (DI SW ICS MNA RD QA QST 2)
2bf349b09f Fixed formatting again 2025-05-19 20:13:52 +03:00
Amerr, Ziad (ext) (DI SW ICS MNA RD QA QST 2)
1393a2bb06 Reformatting, and adding copilot's suggestion 2025-05-19 20:12:07 +03:00
Amerr, Ziad (ext) (DI SW ICS MNA RD QA QST 2)
d944f6591e Skipping permission test error if the user has root privileges 2025-05-19 20:02:59 +03:00
Jeremiah Lowin
e7e301815f Handle template errors 2025-05-13 14:33:11 -04:00
Jeremiah Lowin
6fa7c1704a Improve error handling for tools and resources 2025-05-13 14:19:55 -04:00
Jeremiah Lowin
82aa53e09b Refactor context to avoid unecessary passing 2025-05-06 21:24:29 -04:00
Jeremiah Lowin
c449f1d697 Handle args/kwargs appropriately for various objects 2025-05-04 15:00:26 -04:00
Jeremiah Lowin
517b5358dd
Merge pull request #290 from jlowin/json
use pydantic_core.to_json
2025-04-30 18:12:27 -04:00