csharp-sdk/samples
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Stephen Toub 08b0a04dab
Overhaul McpClientFactory/McpServerFactory (#87)
Handlers are now specified before connecting the client/server. Otherwise, race conditions exist. Handlers move into being a part of the McpClientOptions/McpServerOptions, so that they're provided to the factories. Where relevant, the handlers are specified as part of the capability descriptors, so that they go hand in hand.

The factories are no longer stateful. Instead of allocating a factory and then calling a create method on it, you just call a static factory method.
2025-03-16 12:08:52 -04:00
..
anthropic/tools/ToolsConsole Overhaul McpClientFactory/McpServerFactory (#87) 2025-03-16 12:08:52 -04:00
microsoft.extensions.ai/tools/ToolsConsole Overhaul McpClientFactory/McpServerFactory (#87) 2025-03-16 12:08:52 -04:00
TestServerWithHosting Use DescriptionAttribute and HasDefaultValue in server builder extensions (#46) 2025-03-09 11:16:00 +01:00
README.md Reorganize folders, samples, minor bug fix (#14) 2025-01-18 12:34:13 +01:00

Samples

This directory contains example projects demonstrating how to use mcpdotnet with different LLM SDKs and platforms.

Environment Setup

Before running the samples, you'll need to set up the following environment variables:

  • ANTHROPIC_API_KEY - Required for the Anthropic sample
  • OPENAI_API_KEY - Required for the MEAI/OpenAI sample

Sample Projects

Anthropic Integration

Located in samples/anthropic, this sample demonstrates integration with Anthropic's Claude API using mcpdotnet. The example shows how to:

  • Configure an MCP client for use with Anthropic
  • Map between MCP protocol types and Anthropic SDK types
  • Handle tool invocations and responses

Microsoft.Extensions.AI Integration

Located in samples/microsoft.extensions.ai, this sample shows how to use mcpdotnet with Microsoft's AI SDK. It demonstrates:

  • Setting up an MCP client with MEAI
  • Mapping MCP tools to MEAI function calls
  • Handling streaming responses and tool invocations

Implementation Notes

Each sample focuses on the mapping between MCP types and SDK-specific types, which is the primary integration point when working with different LLM SDKs. The samples provide reusable mapping code that can serve as a starting point for your own implementations.

The complexity of this mapping varies depending on how closely the SDK's design aligns with typical LLM APIs. The provided samples demonstrate best practices for both straightforward and more complex mapping scenarios.

Running the Samples

  1. Clone the repository
  2. Set up the required environment variables
  3. Navigate to the desired sample directory
  4. Run dotnet run to execute the sample

For more detailed examples of mcpdotnet usage, you can also refer to the integration tests in the tests/McpDotNet.IntegrationTests project.