Commit graph

194 commits

Author SHA1 Message Date
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
Eirik Tsarpalis
5e606c1543
Bump package version to 0.1.0-preview.7 (#212) 2025-04-04 19:53:08 +01:00
Aaron Powell
01410df5ad
Add EverythingServer sample (#151) 2025-04-04 11:48:53 -07:00
Stephen Toub
d21d933876
Move notification handler registrations to capabilities (#207) v0.1.0-preview.6
* Move notification handler registrations to capabilities

Currently request handlers are set on the capability objects, but notification handlers are set after construction via an AddNotificationHandler method on the IMcpEndpoint interface. This moves handler specification to be at construction as well. This makes it more consistent with request handlers, simplifies the IMcpEndpoint interface to just be about message sending, and avoids a concurrency bug that could occur if someone tried to add a handler while the endpoint was processing notifications.

* Address more feedback and further cleanup
2025-04-04 13:11:07 -04:00
Stephen Toub
8fcdf95785
Consolidate McpClientException/McpServerException into McpException (#209) 2025-04-03 21:10:57 -04:00
Stephen Halter
d1a3c201a4
Disable response compression for SSE responses (#208) 2025-04-03 17:53:58 -07:00
Eirik Tsarpalis
3b26bf8b1e
Bump package version to 0.1.0-preview.6 (#206) 2025-04-03 20:27:55 +01:00
Esteban Solano Granados
c70dde3feb
[UnitTests] Add more UTs (#139) v0.1.0-preview.5
* + Tests for McpClientExtensions code

* + code coverage for ClientOptions/Capabilities code

---------

Co-authored-by: Esteban Solano <estebanso@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-03 14:18:34 -04:00
Andy Gocke
f652b1a03d
Mark samples as AOT compatible (#184)
* Revert changes to remove APIs

* Apply suggestions from code review

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

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
2025-04-03 14:12:25 -04:00
Stephen Toub
c452dc8e26
Reduce dependencies to 8.x versions of packages (#195)
* Reduce dependencies to 8.x versions of packages

When building for netstandard2.0 or net8.0, the ModelContextProtocol library now only depends on 8.x versions of nuget packages, rather than using the newer 9.x versions. The exception to this are packages that don't have 8.x versions.

This also introduces a net9.0 tfm. When building for net9.0, it'll use 9.x versions of packages.

The PR temporarily removes the Microsoft.Extensions.AI.nupkg reference (the Microsoft.Extensions.AI.Abstractions reference is still very much there). The latest Microsoft.Extensions.AI package on nuget has a System.Text.Json 9.x reference, but the next build to be published drops that down to 8.x as well. Once that build is published, the dependency will be added back, and temporary polyfills (in particular TemporaryAIFunctionFactory) will be deleted.

* Fix StdioClientSessionTransport shutdown

StreamClientSessionTransport's ReadMessageAsync method does await CleanupAsync in its finally. CleanupAsync awaits _readTask. _readTask _is_ ReadMessageAsync. So it's waiting for itself to complete, which will then always timeout. We may want to refactor how this works more in the future, but for now, make sure it doesn't wait for itself.

* Fix dangling requests when server unexpectedly shuts down

If the client makes a request to the server and while waiting for the response the server shuts down, the client hangs. Make sure that when the client's message loops ends due to the server's output it's reading from ends, any pending requests are notified.

* Add net9.0 testing

* Avoid docker port conflicts from test suites running concurrently
2025-04-03 14:01:46 -04:00
Eirik Tsarpalis
1c145a5d52
Hardcode the source generator in one remaining location and simplify McpJsonUtilities. (#204) 2025-04-03 13:42:42 -04:00
Stephen Toub
a04cf6a2f5
Expand a few DI-related tests (#201) 2025-04-03 12:48:23 -04:00
Peder Holdgaard Pedersen
4ecb6bc240
Allow override of name and description of McpClientTool (#165) 2025-04-02 14:05:08 -07:00