Commit graph python-sdk/tests
Author SHA1 Message Date
Akash D
83968b5b2f
Handle SSE Disconnects Properly (#612) 2025-05-02 09:32:46 -07:00
ihrpr
5d8eaf77be
Streamable Http - clean up server memory streams (#604) 2025-05-02 14:59:17 +01:00
ihrpr
74f5fcfa0d
StreamableHttp - client refactoring and resumability support (#595) 2025-05-02 14:49:50 +01:00
ihrpr
cf8b66b82f
use metadata from SessionMessage to propagate related_request_id (#591) 2025-05-02 14:35:17 +01:00
ihrpr
da0cf22355
Wrap JSONRPC messages with SessionMessage for metadata support (#590) 2025-05-02 14:29:00 +01:00
ihrpr
3978c6e1b9
StreamableHttp -- resumability support for servers (#587) 2025-05-02 14:10:40 +01:00
ihrpr
9dfc925090
StreamableHttp client transport (#573) 2025-05-02 13:59:02 +01:00
ihrpr
46523afe30
StreamableHttp - GET request standalone SSE (#561) 2025-05-02 13:52:27 +01:00
ihrpr
78f0b11a09
StreamableHttp - Server transport with state management (#553) 2025-05-02 11:58:54 +01:00
Peter Raboud
2210c1be18
Add support for serverside oauth (#255)
Some checks failed
Check uv.lock / check-lock (push) Has been cancelled
Main branch checks / checks (push) Has been cancelled
Co-authored-by: David Soria Parra <davidsp@anthropic.com>
Co-authored-by: Basil Hosmer <basil@anthropic.com>
Co-authored-by: ihrpr <inna@anthropic.com>
2025-05-01 19:42:59 +01:00
bhosmer-ant
82bd8bc1d9
Properly clean up response streams in BaseSession (#515) 2025-05-01 14:45:47 +01:00
bhosmer-ant
1a330ac672
Add ToolAnnotations support in FastMCP and lowlevel servers (#482) 2025-04-30 14:52:56 +01:00
Samuel Colvin
697b6e8e05
replace inefficient use of to_jsonable_python (#545) 2025-04-26 20:41:19 +02:00
ihrpr
b4c7db6a50
Format files with ruff (#562) 2025-04-23 05:06:51 +01:00
Christian Clauss
babb477dff
Python lint: Ruff rules for comprehensions and performance (#512) 2025-04-15 16:58:33 +02:00
Jerome
c4beb3e8ef
Support custom client info throughout client APIs (#474)
Co-authored-by: Claude <noreply@anthropic.com>
2025-04-10 14:52:01 +01:00
Junpei Kawamoto
da54ea003e
Allow generic parameters to be passed onto Context on FastMCP tools
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-04-10 10:36:46 +01:00
Pol Avec
4e3c196941
Fixes incorrect casting into int for numbers in string format (#384) 2025-03-27 15:14:01 +00:00
evalstate
6d66ab8be0
Fix/base64 handling (Issue #342) (#343)
Co-authored-by: David Soria Parra <167242713+dsp-ant@users.noreply.github.com>
2025-03-27 09:18:02 +00:00
David Soria Parra
9a2bb6a7e7
refactor: Make types.py strictly typechecked. (#336) 2025-03-26 14:21:35 +00:00
David Soria Parra
df2d3a57c2
Fix #355: Fix type error with lifespan context (#368)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2025-03-26 14:18:41 +00:00
David Soria Parra
568cbd1a66
Fix #201: Move incoming message stream from BaseSession to ServerSession (#325)
Co-authored-by: Claude <noreply@anthropic.com>
2025-03-24 14:14:14 +00:00
Marcelo Trylesinski
ae77772ea8
Add strict mode to pyright (#315)
* Add strict mode to pyright

* Apply UP rule

* fix readme

* More correct

* Leave wrong Context for now

* Add strict mode to pyright

* Apply UP rule

* fix readme

* fix

* ignore
2025-03-20 09:13:08 +00:00
ihrpr
08f4e01b8f
add callback for logging message notification (#314) 2025-03-19 09:40:08 +00:00
Samuel Colvin
3775916c5c
lint docs examples (#286)
* lint docs examples

* format
2025-03-14 11:30:57 +00:00
Marcelo Trylesinski
7196604468
Revert "refactor: reorganize message handling for better type safety and clar…" (#282)
Some checks failed
Main branch checks / checks (push) Has been cancelled
This reverts commit 9d0f2daddb.
2025-03-14 09:50:46 +00:00
David Soria Parra
9d0f2daddb
refactor: reorganize message handling for better type safety and clarity (#239)
Some checks failed
Main branch checks / checks (push) Has been cancelled
* refactor: improve typing with memory stream type aliases

Move memory stream type definitions to models.py and use them throughout
the codebase for better type safety and maintainability.

GitHub-Issue:#201

* refactor: move streams to ParsedMessage

* refactor: update test files to use ParsedMessage

Updates test files to work with the ParsedMessage stream type aliases
and fixes a line length issue in test_201_client_hangs_on_logging.py.

Github-Issue:#201

* refactor: rename ParsedMessage to MessageFrame for clarity

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: move MessageFrame class to types.py for better code organization

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>

* fix pyright

* refactor: update websocket client to use MessageFrame

Modified the websocket client to work with the new MessageFrame type,
preserving raw message text and properly extracting the root JSON-RPC
message when sending.

Github-Issue:#204

* fix: use NoneType instead of None for type parameters in MessageFrame

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

* refactor: rename root to message
2025-03-13 13:44:55 +00:00
Marcelo Trylesinski
94d326dbf1
Close unclosed resources in the whole project (#267)
* Close resources

* Close all resources

* Update pyproject.toml

* Close all resources

* Close all resources

* try now...

* try to ignore this

* try again

* try adding one more..

* try now

* try now

* revert ci changes
2025-03-13 10:59:45 +00:00
Henry Mao
fb7d0c8dac
Pyright 2025-03-12 13:56:05 -07:00
Henry Mao
ba184a2667
Ruff 2025-03-12 13:51:35 -07:00
Henry Mao
fd826cc7a6
Fix Websocket Client and Add Test 2025-03-07 22:00:56 +08:00
David Soria Parra
b1942b31c4
Fix #177: Returning multiple tool results (#222)
* feat: allow lowlevel servers to return a list of resources

The resource/read message in MCP allows of multiple resources
to be returned. However, in the SDK we do not allow this. This
change is such that we allow returning multiple resource in
the lowlevel API if needed. However in FastMCP we stick to
one, since a FastMCP resource defines the mime_type in the decorator
and hence a resource cannot dynamically return different mime_typed resources.
It also is just the better default to only return one resource.
However in the lowlevel API we will allow this.

Strictly speaking this is not a BC break since the new return value
is additive, but if people subclassed server, it will break them.

* feat: lower the type requriements for call_tool to Iterable
2025-02-20 21:31:26 +00:00
David Soria Parra
10a85e452d
fix: mark test as pytest.mark.anyio 2025-02-20 11:04:29 +00:00
Jerome
ff22f48365
Add client handling for sampling, list roots, ping (#218)
Adds sampling and list roots callbacks to the ClientSession, allowing the client to handle requests from the server.

Co-authored-by: TerminalMan <84923604+SecretiveShell@users.noreply.github.com>
Co-authored-by: David Soria Parra <davidsp@anthropic.com>
2025-02-20 10:49:43 +00:00
David Soria Parra
faf3a9d7d6
Merge pull request #205 from modelcontextprotocol/issue-192-request-id-test
Add test to verify request ID preservation
2025-02-13 15:10:00 +00:00
David Soria Parra
fbf4acc679
fix: method ordering 2025-02-13 14:54:53 +00:00
Jerome
9abfe775cc
Added failing test 2025-02-13 14:46:57 +00:00
David Soria Parra
41af509bcb
Add test to verify request ID preservation
This test ensures that the server properly preserves and returns the same request ID in responses,
which is a fundamental part of the JSON-RPC protocol. The test initializes the server, sends
requests with custom IDs, and verifies that these IDs are correctly returned.

Github-Issue:#192
2025-02-12 16:32:21 +00:00
David Soria Parra
e5815bd162
docs: update README with lifespan examples and usage
Add comprehensive documentation for lifespan support:
- Add usage examples for both Server and FastMPC classes
- Document startup/shutdown patterns
- Show context access in tools and handlers
- Clean up spacing in test files
2025-02-11 12:16:51 +00:00
David Soria Parra
e598750cba
test: add tests for server lifespan support
Adds comprehensive tests for lifespan functionality:
- Tests for both low-level Server and FastMCP classes
- Coverage for startup, shutdown, and context access
- Verifies context passing to request handlers
2025-02-11 12:16:47 +00:00
David Soria Parra
f10665db4c
tests: cleanup 2025-02-05 11:02:51 +00:00
David Soria Parra
c58adfe3f5
Merge pull request #167 from modelcontextprotocol/davidsp/88-v2
feat: add request cancellation and cleanup
2025-02-04 20:23:05 +00:00
David Soria Parra
27bfde95a4
fix: fix tests 2025-02-04 20:16:30 +00:00
David Soria Parra
08cfbe522a
fix: improve error handling and request cancellation for issue #88 2025-02-04 18:20:17 +00:00
David Soria Parra
827e494df4
feat: add request cancellation and in-flight request tracking
This commit adds support for request cancellation and tracking of
in-flight requests in the MCP protocol implementation. The key
architectural changes are:

1. Request Lifecycle Management:
   - Added _in_flight dictionary to BaseSession to track active requests
   - Requests are tracked from receipt until completion/cancellation
   - Added proper cleanup via on_complete callback

2. Cancellation Support:
   - Added CancelledNotification handling in _receive_loop
   - Implemented cancel() method in RequestResponder
   - Uses anyio.CancelScope for robust cancellation
   - Sends error response on cancellation

3. Request Context:
   - Added request_ctx ContextVar for request context
   - Ensures proper cleanup after request handling
   - Maintains request state throughout lifecycle

4. Error Handling:
   - Improved error propagation for cancelled requests
   - Added proper cleanup of cancelled requests
   - Maintains consistency of in-flight tracking

This change enables clients to cancel long-running requests and
servers to properly clean up resources when requests are cancelled.

Github-Issue:#88
2025-02-03 20:50:05 +00:00
David Soria Parra
888bdd3c34
tests for issue 88 2025-02-03 14:03:41 +00:00
David Soria Parra
0d3e02f6a2
fix: standardize resource response format
Github-Issue:#141
2025-02-03 11:33:32 +00:00
Jerome
444edf6760
Merge pull request #180 from modelcontextprotocol/jeremy/relax-pydantic
Relax pydantic, pydantic-settings, and uvicorn requirements
2025-01-31 07:07:59 +13:00
David Soria Parra
5e19c7cf73
Merge pull request #176 from sheffler/fixFirstProgressReport
progress_token is 0 on first tool-call and the return is taken mistakenly
2025-01-30 16:00:01 +00:00
jeremy
defd52b2d6
Fix comment about pydantic versioning 2025-01-30 10:21:03 -05:00