Commit graph swift-sdk/Tests/MCPTests
Author SHA1 Message Date
yehorsobko
a0ae212ebf
Improvements and fixes (#223)
Some checks failed
CI / Test (macos-latest, Swift 6.1.0) (push) Has been cancelled
CI / Test (ubuntu-latest, Swift 6.1.0) (push) Has been cancelled
CI / MCP Conformance Tests (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Linux Static SDK Build (6.1.2 - ubuntu-latest) (push) Has been cancelled
* feat: added http transport context to the task local execution

* fix: added refresh_token to the grantTypes for DCR

* chore: updated documentation
2026-04-29 14:34:21 +03:00
yehorsobko
cb6a62f7c2
feat: auth improvements (#217)
* feat: improvement to oauth resources resolution

* feat: improvements to refreshToken procedure and updates to unit tests

* feat: improvements to documentation of clien_id
2026-04-17 17:34:59 +03:00
Maksym Mova
6132fd4b5b
V0.12.x (#215)
* fix #203 NetworkTransport race, with main-isolated variables (#206)

Co-authored-by: wti <wti@users.noreply.github.com>

* feat/auth: Authentication implementation (#205)

* feat: added authentication

* feat(auth): improvement to error handling

* feat(auth): updated errors and tests in OAuthClientRegistrar

* feat(auth): updated ci conformance package version

* feat(auth): bumped node version

* feat(auth): updated ci conformance step

* feat(auth): improvement to Linux support

* chore: added docc plugin

* chore: added spi yml

* chore: added documentation step to ci

* chore: increased timeout for test from 5 to 10m

---------

Co-authored-by: Paal Øye-Strømme <paal.o.eye@gmail.com>
Co-authored-by: wti <wti@users.noreply.github.com>
Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
2026-03-24 11:05:22 +02:00
yehorsobko
973b46b8f7
feat: 2025-11-25 review fixes (#201)
* fix: review fixes of the latest changes

* fix: updated unit tests

* chore: more conformance compliance improvements

* chore: reverted protocol changes

* chore: more compliance improvements

* chore: more conformance compliance improvements

* chore: improvements to the backcompat and updated to Tool unit tests

* chore: ci update
2026-03-03 17:33:28 +02:00
Maksym Mova
6112a3995a
V0.11.x (#199)
* Support 2025-06-18 Spec (#167)

* Support OpenAI _meta for Tool

* Update init

* Add title and outputSchema

* Concurreny issue

* General fields

* Add Generate Fields to Server elements

* 4 tab spacing

* Update Version

* Elicitation

* Format

* More tests and inits

* Elicitation in README

* Fix orphaned test

* Add title to more structs

* Public init

* Fix meta validation and make tests more generic

* Format and make Result properties public again

* Revert more visibility changes

* feat: 2025-11-25 phase 1, includes Version, Icon, Progress (#181)

* chore: fixed unit tests

* feat: added icon and progess base structs

* feat: added progress notification and meta to callTool

* feat: added tests

* feat: simplified RequestMeta encoding/decoding

* tests: added unit test to track progress

* chore: rebased v0.11.x

* feat: implemented cancellation

* feat: added overloaded callTool method

* fix: encoding Response _meta fix

* chore: added old version to the versions list

* feat: 2025-11-25 phase 2; added Logging and Completions (#196)

* feat: added Logging and Completions

* feat: updated EmbeddedResource for the latest spec

* chore: changed encoding of meta in Prompts to encodeIfPresent

* feat: compliance tests + http server transport (#197)

* feat: http server transport

* feat: added http server transport

* feat: removed unused files

* feat: added conformance tests

* feat: improved conformace testing

* chore: removed redundant files

* feat/2025-11-25: sampling, elicitation, roots (#198)

* feat: Roots implementation

* feat: added unit testing

* feat: improved unit tests and fixed NetworkTransport crash

* feat: implemented sampling and elicitation

* feat: improved sampling tests

* feat: improved elicitation tests

* feat: improved confirmance tests

* feat: improved Prompts unit tests

* feat: removed test code

* feat: updated conformance tests

* chore: removed redundant commas

* chore: removed 6.0.3 swift version from ci

* chore: improved unit tests a little bit

* chore: update README.md

* chore: add server progress tracking example to README.md

* chore: updated README.md

* chore: updated transports table formatting

* chore: updated MockNetworkConnection

---------

Co-authored-by: Austin Evans <austinjevans@me.com>
Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
2026-02-19 13:09:31 +02:00
Yifan Liu
fb6fffbecd
fix: allow description field to be absent from Tool (#159)
* fix: allow description field to be absent from `Tool`
* description field is not a requried field of Tool

* Apply suggestions from code review

* Update Tests/MCPTests/ToolTests.swift

---------

Co-authored-by: Mattt <mattt@me.com>
2025-09-07 04:30:19 -07:00
Mattt
0121dccf7e
Add requestModifier property to HTTPClientTransport (#152)
* Add requestModifier property to HTTPClientTransport

Co-authored-by: Tim Wang <tim.wang@ing.com>

* Add test coverage

---------

Co-authored-by: Tim Wang <tim.wang@ing.com>
2025-08-10 06:28:08 -07:00
Mattt
63fd276dbd
Implement in-memory / passthrough transport (#122)
* Implement in-memory / passthrough transport

* Add InMemoryTransport to README
2025-08-10 05:52:20 -07:00
Mattt
f3b9ba4a59
Make Tool.inputSchema nonoptional (#123) 2025-08-10 05:34:47 -07:00
Mattt
36865fb056
Update inputSchema example usage (#136)
* Update Tool inputSchema in README example usage

* Update inputSchema usage in Tool tests
2025-06-12 02:57:04 -07:00
Mattt
a59b50bf5a
Update Client.connect(transport:) to automatically send initialize request (#100)
* Update Client to automatically call initialize in connect

* Make Client.connect(transport:) return value discardable

* Fix example usage in README

* Update example code in transports to remove initialize call

* Deprecate initialize method

* Update tests

* Update README

* Fix sampling tests

* Fix race condition tests
2025-05-26 06:04:38 -07:00
Mattt
3b505ee575
Improve ergonomics of prompt and sampling message initialization (#120)
* Improve ergonomics of prompt and sampling message initialization

* Deprecate previous / existing Message initializers
2025-05-26 05:25:02 -07:00
Mattt
fac4df6b1a
Add support for sampling (#119)
* Add UnitInterval type

* Add test coverage for UnitInterval

* Add support for sampling

* Add integration tests for sampling
2025-05-26 04:57:24 -07:00
Mattt
ddde66dc08
Add test coverage for base64 data helper methods (#114) 2025-05-26 04:36:13 -07:00
Mattt
fec680a243
Prevent double continuation resumption in client (#113)
* Prevent double continuation resumption in client

Consolidate request removal and continuation resumption logic to ensure each request's continuation is resumed exactly once, preventing "SWIFT TASK CONTINUATION MISUSE" errors during network failures.

* Fix race condition test
2025-05-26 04:36:01 -07:00
Mattt
87f33d022a
Improve NetworkTransport and add test coverage (#108)
* Improve NetworkTransport and add test coverage

* Remove the weakTransport check since actors have special memory management rules

* Use Task.sleep(for:) consistently

* Always start connection in connect

* Run NetworkTransportTests serially
2025-05-07 10:36:54 -07:00
Mattt
720a8102e9
Implement client protocol version negotiation in server initialization (#107)
* Implement client version negotiation in server initialization

* Add test coverage for version negotiation

* Make Version.supported and Version.negotiate() APIs internal to not create new surface area
2025-05-07 05:58:11 -07:00
Mattt
bdaa2585c5
Delay SSE GET connection until after session ID is established (#97)
* Delay SSE GET connection until after session ID is established

- Add a signaling mechanism to ensure the SSE streaming task waits for the initial session ID to be set before attempting the GET connection.
- Use a TaskGroup to race between session ID signal and a 10-second timeout, logging the outcome.
- Trigger the signal when a session ID is received for the first time from any response.
- Add detailed logging for all code paths to aid debugging and clarify connection timing.
- Clean up signal resources on disconnect to prevent leaks.

This addresses the initialization timing issue where the SSE GET could be attempted before the session was established, as discussed in MCP PR #91.

* Update tests for SSE timing

* Use configurable timeout for acquiring session ID

* Remove Actor protocol conformance for HTTPClientTransport

* Configure shorter session ID timeout for tests

* Add documentation comments to HTTPClientTransport

* Rename sessionIDWaitTimeout to sseInitializationTimeout
2025-05-06 06:49:48 -07:00
Mattt
3ff1085e01
Use EventSource for SSE implementation (#96)
* Add package dependency for github.com/loopwork-ai/EventSource

* Use EventSource for SSE implementation

* Refactor response stream and content type handling

Co-authored-by: Stephen Tallent <stallent@mercury.io>

* Conditionalize use of streaming for supported platforms

* Refactor conditional platform handling

* Conditionalize code and package dependency on Linux

---------

Co-authored-by: Stephen Tallent <stallent@mercury.io>
2025-05-06 05:45:40 -07:00
Mattt
48c19c282b
Document Client usage with HTTPClientTransport (#77)
* Add test coverage for Client with HTTPClientTransport

* Configure HTTP client transport to stream by default

* Add example usage of streaming HTTP transport to README

* Explicitly set streaming to false in test
2025-04-27 09:29:24 -07:00
Ayal Spitz
f6e401aa97
Fix event stream line parsing to handle CRLF and empty lines correctly (#89)
* Optimized code in `connectToEventStream` to use `.lines` computed value of `AsyncSequence` to produce a `AsyncLineSequence` instead of building a lines manually.

* - Reverter use of `lines` (it swallows newlines)
- Fiexed original issue I experienced with line 229 `while let newlineIndex = buffer.firstIndex(of: "\n") {` not handling "\r\n" properly
- Added unit test to test for "\r\n" scenario
- Simplified `end of event` test - `line` creation trims newline, added code trims carriage return. Only thing that should be left is an empty line
2025-04-27 06:50:08 -07:00
Stephen Tallent
99517b0564
Update AnyNotification to include notification params (#86)
* Update AnyNotification to not wipe out params that come with a notification

* Add test coverage for notification with params

* Allow params to be omitted when empty

---------

Co-authored-by: Stephen Tallent <stallent@mercury.io>
Co-authored-by: Mattt Zmuda <mattt@loopwork.com>
2025-04-27 06:47:38 -07:00
Mattt
25dee3bb4c
Send initialized notification from client instead of server (#85) 2025-04-21 14:43:33 -07:00
Mattt
d583151871
Add streamable HTTP transport for clients (#70)
* Rename file to Transport.swift

* Rename file to StdioTransportTests.swift

* Add .index-build/ to .gitignore

* Implement HTTP client transport

* Add test coverage for streamable HTTP client transport

* Conditionally import FoundationNetworking

* Conditionalize streaming for unsupported platforms

* Import FoundationNetworking in tests

* Add 5 minute timeout to CI jobs

* Remove debug logging

* Formatting

* Skip SSE tests on platforms that don't support streaming
2025-04-15 09:06:29 -07:00
Mattt
4143f35b41
Implement Tool.Annotations (#47) 2025-04-15 05:42:44 -07:00
Mattt
c748bc1549
Add support for audio content in prompts and tool results (#73) 2025-04-15 05:41:28 -07:00
Mattt
82f4fd29b3
Add support for JSON-RPC batching (#67)
* Update StdioTransport documentation comments to indicate support for JSON-RPC batches

* Add server support for JSON-RPC batching

* Add client support for JSON-RPC batching

* Fix bug that caused error messages to be wrapped unnecessarily
2025-04-10 12:13:41 -07:00
Mattt
2a978d175e
Fix testServerHandleInitialize flake (#68) 2025-04-10 12:09:06 -07:00
Mattt
1e61f205a1
Add support for Linux with glibc (#61)
* Conditionally import Glibc on Linux for fcntl calls

* Extract transport implementations into separate files

* Fix warning in test

* Add ubuntu-latest to CI test matrix

* Switch to vapor/swiftly-action for setup step

* Configure Prettier extension to format GitHub Actions workflows

* Setup with different actions depending on platform

* Rename step

* Rename job

* Update README
2025-04-10 05:22:56 -07:00
Mattt
20d4fe6f5a
Update Client.listTools return type to include next cursor (#54) 2025-04-09 16:20:55 -07:00
Mattt
0725c46969
Remove top-level MCP enumeration (#53) 2025-04-04 12:11:27 -07:00
Mattt
09da2a1c01
Rename Error to MCPError (#44)
* Rename Error to MCPError

* Conform MCPError to Swift.Error

* Use unqualified Error instead of Swift.Error

* Use unqualified MCPError instead of MCP.MCPError

* Rename file back to Error.swift

* Introduce top-level MCP namespace with nested Error typealias to provide deprecation notice for existing usage of MCP.Error

* Fix markup for MCP enum warning
2025-04-03 05:25:00 -07:00
Mattt
a9bcbf9ad9
Update transports to send and receive data instead of strings (#42)
* Update transports to send and receive data instead of strings

* Rename MockTransport helper methods

* Adopt Task.sleep(for:...) instead of variant taking nanoseconds

* Update comment

* Revert inadvertant change to visibility of send method
2025-04-03 04:42:56 -07:00
Mattt
de829ee648
Add configurable strict mode for MCP client initialization (#43)
* Add configurable strict mode for MCP client initialization

* Rename checkCapability to validateServerCapability
2025-04-03 04:33:50 -07:00
Adam Wulf
19857af5bf
Fix/decode tool call (#36)
* Adding unit test

* Decode entire request to strongly typed Method call. This allows NotRequired parameters to properly decode from null, which wouldn't be possible when decoding from the 'null' JSON encoding directly.
2025-03-31 05:34:33 -07:00
Mattt
d55140bc46
Import System package when available (#34)
* Import System package when available

* Add isResourceTemporarilyUnavailable helper method to reduce number of imports of System / SystemPackage
2025-03-31 05:30:45 -07:00
Adam Wulf
da97a3db3c
Add unit test to check that AnyRequest handles missing parameters (#24)
* Add unit test to check that AnyRequest handles missing parameters

* Conform Value to NotRequired

* Add test for decoding AnyRequest with empty parameters

---------

Co-authored-by: Mattt Zmuda <mattt@loopwork.com>
2025-03-19 05:41:50 -07:00
Mattt
75322c3baf
Ensure Request decoder handles missing/null params correctly (#22) 2025-03-18 10:02:05 -07:00
Mattt
2510dda70e
Add server initialization hook (#19) 2025-03-18 09:47:54 -07:00
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 Zmuda
06d5e9a093
Temporarily comment out hanging test 2025-02-11 15:22:41 -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