Commit graph swift-sdk/Sources/MCP
Author SHA1 Message Date
Mattt
59b6b755c0
Revert "Update capabilities to be expressible by Boolean literals (#16)" (#18)
This reverts commit 3e628db6d8.
2025-03-17 05:42:27 -07:00
Mattt
6f1f65a392
Allow params field to be omitted in requests for methods that don't require them (#17)
* Allow `params` field to be omitted in requests for methods with empty parameters

* Add ping request to roundtrip test

* Generalize decoding of non-required parameters
2025-03-17 05:26:47 -07:00
Mattt
3e628db6d8
Update capabilities to be expressible by Boolean literals (#16)
* Conform Server.Capabilities types to ExpressibleByBooleanLiteral

* Conform Client.Capabilities types to ExpressibleByBooleanLiteral

* Use Boolean literatls for capabilities in tests

* Update README
2025-03-17 04:35:03 -07:00
Mattt
a2a0044abb
Remove nonstandard read and list capabilities for resources (#15)
* Remove nonstandard read and list capabilities for server

* Update README
2025-03-17 04:17:23 -07:00
Mattt
a62e51a61c
Make CallTool.Result.isError optional (#11) 2025-03-14 06:24:46 -07:00
Sash Zats
c63a872a69
Fix client parsing (#8)
* Allow decoding Decodable type directly from Value

Summary: I noticed we are not converting value associated with response to the strong types requests recorded
This change will help to decode the value type later once we support the rest of plumbing (next commit)

* Store and pass original request when response arrives

Summary: Looks like there were multiple issues with parsing response:
1. It appears that we would mistakenly pass response both for response and request arguments in the private func handleResponse(_ response: Response<AnyMethod>, for request: Any)
2. Later I couldn't figure out how to win against swift type system, so ended up creating a type-erased request to store in the pendingRequests instead of original type under Any (that wouldn't allow to downcast original type later)

Test Plan:

1. Standup iMCP client from https://github.com/loopwork-ai/iMCP
2. Create a dummy project setting up MCP client against "/private/var/folders/26/8gncz37x7slbfrr95d9jcr400000gn/T/AppTranslocation/62ADEC4D-3545-4E98-A612-0E6DF52CE525/d/iMCP.app/Contents/MacOS/imcp-server" and call initialize

Note response is being parsed correctly and client.initialize() does not hang indefinitely

* Fix warning: 'Cast from Client.AnyPendingRequest to unrelated type Client.PendingRequest<Any> always fails'

* Fix warning: 'Conditional cast from NWError to NWError always succeeds'

* Uncomment code in RoundtripTests

* Formatting

* Reorganize declarations

* Inline JSONDecoder extension

* Expand roundtrip tests

---------

Co-authored-by: Sash Zats sash@zats.io <>
Co-authored-by: Mattt Zmuda <mattt@loopwork.com>
2025-03-13 11:39:46 -07:00
Mattt
893614e241
Update server to always send response to invalid messages (#6) 2025-03-04 06:25:40 -08:00
Mattt
d0364a936a
Throw more specific networking errors in NetworkTransport (#5) 2025-03-04 06:18:44 -08:00
Mattt
b761d3ea6f
Properly propagate errors in NetworkTransport receive stream (#4)
Changes AsyncStream to AsyncThrowingStream to ensure network errors are correctly propagated to callers. Updates receive() to handle errors from the underlying message stream.
2025-03-04 06:05:41 -08:00
Mattt
1f5f8d64b9
Add configurable strict mode for MCP server initialization (#3)
Adds a Configuration struct to control server behavior around client initialization.
When strict mode is enabled, server enforces MCP spec requiring clients to initialize
before sending requests. Default mode is more permissive for non-compliant clients.
2025-03-04 06:02:43 -08:00
Mattt
136762158e
Add NetworkTransport (#2) 2025-02-27 14:50:50 -08:00
Mattt Zmuda
be1e9583f8
Initial implementation 2025-02-11 15:22:35 -08:00
Mattt Zmuda
cc603d35fe
Initial commit 2025-02-05 11:13:57 -08:00