Commit graph

206 commits

Author SHA1 Message Date
Stephen Halter
e3ff552824
Improve testing for StreamableHttpHandler and IdleTrackingBackgroundService (#345) v0.1.0-preview.11
* Add idle session pruning tests
* Remove redundant CTS from StreamableHttpHandler
  * StreamableHttpServerTransport.HandlePostRequest already creates the equivelant CTS
    which DeleteRequest_CompletesSession_WhichCancelsLongRunningToolCalls verifies
* Fix accept header validation for GET
* Use InvalidOperationException for transport-not-connected errors in doc comments
* Fix flaky Cancellation_ThrowsCancellationException test
2025-04-24 10:49:02 -07:00
Peder Holdgaard Pedersen
4fd3ebf3fe
Fixed issue preventing client example from compiling. (#346) 2025-04-23 11:58:18 -07:00
Ferry To
f2ae0cace6
Clarify McpClientTool inherits from AIFunction in README.md
Co-authored-by: Stephen Halter <halter73@gmail.com>
2025-04-21 18:57:59 -07:00
dogdie233
0c9e91f98c
Emit root-relative /message endpoint when using SSE Server (#323) 2025-04-20 14:31:48 -07:00
Jeff Handley
9505eb5160
Bump version to v0.1.0-preview.11 (#332) 2025-04-18 17:56:28 -07:00
Stephen Halter
7dcba357d4
Add server-side Streamable HTTP transport support (#330) v0.1.0-preview.10
- Changes IJsonRpcMessage to an abstract base class so RelatedTransport will always be available
- Streamable HTTP supports multiple concurrent HTTP request with their own indpendent SSE response streams
- RelatedTransport indicates the source or destination of the JsonRpcMessage

- Changes the default RequestId to a JSON number for better compatibility with MCP servers in the wild
2025-04-18 17:07:23 -07:00
Stephen Toub
7d77be68cf
Clean up (use of) McpException and McpTransportException (#321)
* Clean up (use of) McpException

* Replace McpTransportException with InvalidOperationException

* Add cancellation test
2025-04-18 09:25:29 -07:00
Stephen Toub
d65ddce268
Fix HandlesIProgressParameter test sporadically failing in CI (#327) 2025-04-18 09:23:19 -07:00
Stephen Toub
b0cd6541ce
Add WithTools/Prompts overloads that accept McpServerTool/Prompts (#319)
To avoid folks needing to know how you should be registering tool instances into DI.
2025-04-16 15:06:19 -04:00
Stephen Toub
227f440ab9
Support progress notifications with McpClientTool and McpClientExtensions.CallToolAsync (#312) 2025-04-16 09:03:07 -04:00
Stephen Toub
90748b1198
Delete faulty assert (#313)
We need better coverage of Subscribe/Unsubscribe separately, but for now this assert is bad.
2025-04-15 16:00:43 -07:00
Jeff Handley
c1e294ca05
Bump version to 0.1.0-preview.10 (#315) 2025-04-15 11:14:44 -07:00
Stephen Toub
312aede7d6
Clean up logging (#286) v0.1.0-preview.9 2025-04-14 10:55:45 -04:00
Mike Alhayek
dc544f929b
Remove unessesary $ and fix some typos (#305) 2025-04-14 10:47:13 -04:00
Stephen Halter
9c124b1770
Add StreamableHttpHandler and WithHttpTransport (#291)
* Simplify ModelContextProtocol.AspNetCore README

* Add StreamableHttpHandler

* Use "docker info" in CheckIsDockerAvailable

* Call WithHttpTransport in samples, tests and README

* Cleanup test namespaces

* Add CanConnect_WithMcpClient_AfterCustomizingRoute test

* Simplify relative URI handling

* Handle request made directly to the MapMcp route pattern

* Add Messages_FromNewUser_AreRejected test

* Fix README

* Shorten UserIdClaim ValueTuple names

* Remove MaxReconnectAttempts and ReconnectDelay from SseClientTransportOptions

- Add proper AdditionalHeaders support
2025-04-14 10:15:33 -04:00
じゅううん
bca5d2609d
Add AdditionalHeader handling to ReceiveMessageAsync (#295) 2025-04-13 14:49:40 -07:00
Liudmila Molkova
d6cc65aced
OpenTelemetry: context propagation and semconv update (#262) 2025-04-12 22:12:11 -04:00
Mike Alhayek
f2fd2046f3
Fix the docs and make the more readable (#281) 2025-04-12 08:41:41 -04:00
Stephen Toub
f4c87f5e2f
Wrap each request in a service scope (#276)
* Wrap each request in a service scope

* Change request/notification delegates to return ValueTask

* Address feedback
2025-04-11 19:19:12 -04:00
Jeff Handley
f1cc2d81de
Workflow refactoring and improvements (#273)
* Remove code coverage PR commenting

* Only run markdown-link-check when markdown files are updated

* Declare CI workflow permissions

* Refactor release workflow and declare permissions

* Pin all actions to SHAs

* Run CI manually, on all pushes to main, or if code changes in a PR

* NuGet publishing doesn't need any permissions
2025-04-11 12:18:17 -07:00
Eirik Tsarpalis
adb95c8d53
Bump version to 0.1.0-preview.9 (#284) 2025-04-11 18:04:36 +01:00
Eirik Tsarpalis
ce4e6586d2
Expose a JsonSerializerOptions setting in the prompts APIs (#279) v0.1.0-preview.8
* Expose a JsonSerializerOptions setting in the prompts APIs

* Change namespace for workaround converter.
2025-04-11 18:02:21 +01:00
Stephen Toub
a896fa8055
Delete some dead methods from Log.cs (#277) 2025-04-11 10:12:55 +01:00
Stephen Toub
c88afe8d86
Augment McpServerTool/Prompt docs with details of parameter/result marshaling (#271)
* Augment McpServerTool/Prompt docs with details of parameter/result marshaling

* Address feedback
2025-04-11 00:05:09 -04:00
Eirik Tsarpalis
e3aa54eb3c
Disable STJ reflection for testing. (#266)
* Disable STJ reflection for testing.

* Remove params method and redundant overload.

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-10 16:02:00 +01:00
Stephen Toub
45dcfe07ca
Fix CreateMessageRule.Role to be of type Role (#264) 2025-04-10 10:51:41 -04:00
Rob Chambers
77871c5aac
AI seeded comments from robch and then edited by stephentoub (#238)
* AI generated `///` comment updates

* Fix compilation issues

* Fix incorrect XML comment structure

* Update all Client comments

* Update all Configuration comments

* Update all Messages comments

* Update all Transport comments

* Update all Types comments

* Update all Server comments

* Undo some commenting

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-10 01:30:44 -04:00
Eirik Tsarpalis
07300389ee
Bump version to 0.1.0-preview.8 (#256) 2025-04-09 19:19:24 +01:00
Eirik Tsarpalis
39ab6cde0d
Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible. (#254) v0.1.0-preview.7
* Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible.

* Fix merge conflicts.

* Update tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj

Co-authored-by: Stephen Halter <halter73@gmail.com>

* Revert "Fix merge conflicts."

This reverts commit 852169b96786bad2144795540fa164e20b4b197e.

* Fix merge conflicts

---------

Co-authored-by: Stephen Halter <halter73@gmail.com>
2025-04-09 19:16:53 +01:00
Stephen Halter
08f9cdbf7d
Fix race in TransportBase.SetConnected (#253)
* Fix race in TransportBase.SetConnected

- Previously the ChannelWriter could already be completed if multiple
  threads raced in SetConnected(false)

* Fix WriteMessageAsync IsConnected test
2025-04-09 19:10:51 +01:00
Stephen Halter
b3a5a82544
Use TryAddEnumerable for McpServerOptionsSetup (#252) 2025-04-09 10:41:34 -07:00
token
cae5dff318
Improve SSE response handling and URI construction in SseClientSessio… (#251) 2025-04-09 08:33:49 -07:00
Dominik Guhr
43266ad268
Fixes #248 - Add CultureInfo.InvariantCulture to string interpolation… (#249)
* Fixes #248 - Add CultureInfo.InvariantCulture to string interpolation for langitude and longitude so the sample works everywhere.

* Update samples/QuickstartWeatherServer/Tools/WeatherTools.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-09 09:08:27 -04:00
Stephen Toub
0c502c43af
Update M.E.AI to latest version (#241)
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
2025-04-09 09:03:24 +01:00
Stephen Toub
dfafebd8fe
Avoid propagating server tool exception message to client (#242)
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
2025-04-09 08:55:13 +01:00
Jeff Handley
b9c0f269d6
Update markdown-link-check to ignore external links causing 403 in CI (#246)
* Update markdown-link-check to ignore external links causing 403 in CI

* Apply wildcards on ignored links

* Bump version of mlc to latest to gain --ignore-links arg

* Do not warn on redirects from markdown-link-check action

* Do not warn on redirects from markdown-link-check action

* Update comment
2025-04-09 08:14:09 +01:00
Tyler Kendrick
03e3094dcc
Fix and enhance cancellation operations across MCP Sessions. (#179)
* Propagate CancellationToken request cancellation to remote endpoint

* Refactor existing tests to have a shared base class

* Add cancellation tests

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-08 16:12:12 -04:00
Jeff Handley
4dd2f42b82
Add SECURITY.md (#239) 2025-04-08 11:43:02 -07:00
Stephen Halter
bab74d5895
Fix StdioServerTransport.DisposeAsync hang (#235)
- It's not just Unix, it's all platforms that can hang
- Windows doesn't hang on Ctrl-C because that triggers
  the end of the Stream, but that doesn't help in IHostApplicationLifetime.StopAsync() scenarios

4e9627e311/src/libraries/System.Console/src/System/ConsolePal.Unix.ConsoleStream.cs (L13)
4e9627e311/src/libraries/System.Console/src/System/ConsolePal.Windows.cs (L1149)
2025-04-08 10:20:16 -07:00
Eirik Tsarpalis
3e21f3594a
Remove McpServerConfig and have McpClientFactory accept IClientTransport instances directly. (#230)
* Remove McpServerConfig and have McpClientFactory accept IClientTransport instances directly.

* Address feedback and use lists when representing stdio arguments.

* Use "Name" for transport descriptors and "EndpointName" for MCP clients and servers.

* Update code samples.

* Fix source file naming
2025-04-08 17:37:41 +01:00
Esteban Solano Granados
8bd9ee81c0
Fix api.weather.gov/points response handling in WeatherTools (#134) 2025-04-07 22:39:10 -07:00
Stephen Toub
3b83ad4103
Enable servers to log to the clients via ILogger (#229)
* Enable servers to log to the client via ILogger

* Address feedback
2025-04-07 23:16:42 -04:00
Stephen Halter
3a2e9a228d
Fix race in KestrelInMemoryConnection (#233)
* Also remove some duplication from WithStdioServerTransport and WithStreamServerTransport
2025-04-07 14:49:32 -07:00
Stephen Toub
82510d5629
Add server "completions" capability (#232)
* Split apart Capabilities.cs

No code changes, just moving each type to its own file.

* Add server completions capability
2025-04-07 16:59:37 -04:00
Eirik Tsarpalis
ac0bc3a1f1
Bump xunit.v3 to 2.0.0 (#231) 2025-04-07 14:46:24 -04:00
Stephen Toub
5d7c2a1a0f
Stop the host when the single session server service finishes (#226)
* Stop the host when the single session server service finishes

* Add test
2025-04-07 12:45:17 -04:00
Stephen Toub
03dc90aa33
Use strong-typing of params in most remaining McpClientExtensions methods (#224) 2025-04-07 11:30:42 -04:00
Stephen Halter
faf12b6a94
Use Kestrel for all in-memory HTTP tests (#225)
* Add route pattern parameter to MapMcp
* Add configureOptionsAsync
* Use Kestrel for all in-memory HTTP tests
* Use ApplicationStopping token for SSE responses
* Use RegisterNotificationHandler in MapMcp tests
* Work around SocketsHttpHandler bug where it doesn't call DispseAsync on the stream returned by the ConnectCallback
2025-04-06 19:27:17 -07:00
Stephen Toub
848c9df433
Allow notification handlers post-creation temporary registration (#223)
- We still allow notification handlers to be configured pre-creation, eliminating any race conditions that may result from missed notifications. But now we also allow for post-creation notification handler registration.
- Handlers may now also be removed. This permits temporary registrations that may be created in a scoped manner.
- Registration handling is thread-safe.
- Handlers are now cancelable.
- Exceptions from notification handlers trigger all normal exception handling in the dispatch pipeline.

This also:
- Adds a WithStreamServerTransport as a counterpart to WithStdioServerTransport. The latter was used in several tests in a hacky way, and that's now simplified via the former's existence.
2025-04-06 21:17:00 -04:00
Stephen Toub
f135355bf9
Propagate fix from AIFunctionFactory to TemporaryAIFunctionFactory (#215) 2025-04-04 21:55:33 -04:00