Skip to content

Commit 1c3d7fe

Browse files
committed
docs(README): introduce new features and adjust section ordering
1 parent d2d6901 commit 1c3d7fe

File tree

1 file changed

+64
-52
lines changed

1 file changed

+64
-52
lines changed

README.md

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
![NuGet Version](https://img.shields.io/nuget/vpre/ModelContextProtocol.NET.Server)
44

5-
A C# SDK implementation of the Model Context Protocol (MCP), enabling seamless integration between AI models and development environments.
6-
7-
## Overview
8-
9-
ModelContextProtocol.NET is a native .NET implementation of the Model Context Protocol, designed to facilitate communication between AI models and development environments. This SDK provides a robust foundation for building AI-powered tools and applications in the .NET ecosystem.
5+
A C# SDK implementation of the Model Context Protocol (MCP).
106

117
## Features
128

@@ -25,59 +21,77 @@ ModelContextProtocol.NET is a native .NET implementation of the Model Context Pr
2521

2622
## Demo
2723

28-
The repository includes a fully functional calculator demo that showcases the basic capabilities of the MCP implementation. This demo serves as a practical example of how to integrate and use the protocol in your applications.
29-
30-
## Technical Details
31-
32-
### Architecture
33-
34-
The project is structured into multiple components:
35-
36-
- **Core Library**: Contains the fundamental protocol implementation
37-
- **Server Components**: Handles communication and request processing
38-
- **Demo Implementation**: Provides a working example with a calculator application
39-
40-
### Key Benefits
41-
42-
- **Native AOT Support**: Fully compatible with .NET Native AOT compilation for optimal performance
43-
- **Modular Design**: Clean separation of concerns allowing for flexible implementation
44-
- **Standard Compliance**: Implements the Model Context Protocol specification
24+
See `src/ModelContextProtocol.NET.Demo.Calculator` for a fully functional calculator demo that covers:
25+
- Logging setup
26+
- Tool handler implementation
27+
- Request/response handling
28+
- Error management
4529

4630
## Getting Started
4731

4832
Install [the server package](https://www.nuget.org/packages/ModelContextProtocol.NET.Server):
4933

5034
```bash
51-
dotnet add package ModelContextProtocol.NET.Server
35+
dotnet add package ModelContextProtocol.NET.Server --prerelease
5236
```
5337

54-
The easiest way to get started is to look at the calculator demo in `src/ModelContextProtocol.NET.Demo.Calculator`.
55-
Here's a quick example of how to set up an MCP server:
38+
For hosting integration, add [the server hosting package](https://www.nuget.org/packages/ModelContextProtocol.NET.Server.Hosting):
5639

40+
```bash
41+
dotnet add package ModelContextProtocol.NET.Server.Hosting --prerelease
42+
```
43+
44+
### A. Without Hosting
5745
```csharp
5846
// Create server info
5947
var serverInfo = new Implementation { Name = "Calculator Demo Server", Version = "1.0.0" };
6048

6149
// Configure and build server
62-
var server = new McpServerBuilder(serverInfo)
63-
.AddStdioTransport()
64-
// see below for logging configuration
65-
.ConfigureLogging(logging => ...)
66-
.ConfigureTools(tools => tools.AddHandler<CalculatorToolHandler>())
67-
.Build();
68-
69-
// Start the server
50+
var builder = new McpServerBuilder(serverInfo).AddStdioTransport();
51+
builder.Services.AddLogging(<see below>);
52+
builder.Tools.AddHandler<YourToolHandler>();
53+
builder.Tools.AddFunction(
54+
name: "YourToolName",
55+
description: "YourToolDescription",
56+
parameterTypeInfo: YourParameterTypeJsonContext.Default.YourParameterType,
57+
handler: (YourParameterType parameters, CancellationToken ct) => {
58+
// Your tool implementation
59+
}
60+
);
61+
// ...
62+
63+
var server = builder.Build();
7064
server.Start();
65+
await Task.Delay(-1); // Wait indefinitely
66+
```
67+
68+
69+
### B. With Hosting
70+
71+
```csharp
72+
var builder = Host.CreateApplicationBuilder();
73+
builder.Services.AddMcpServer(serverInfo, mcp => {
74+
mcp.AddStdioTransport();
75+
// same as without hosting
76+
}, keepDefaultLogging: false); // clear default console logging
77+
// ...
78+
79+
var host = builder.Build();
80+
await host.RunAsync();
7181
```
7282

7383
### Logging Configuration
7484

7585
`McpServerBuilder` uses `Microsoft.Extensions.Logging.ILogger` as the logging interface.
76-
Since stdio transport is used, logs can't be sent to the console.
77-
You need to configure a logging provider that can write to a file or other logging destination.
86+
When stdio transport is used, logs can't be sent to the console.
87+
You need to configure a logging provider that writes to other logging destination.
7888

7989
If no logging provider is configured, a null logger will be used, resulting in no logs being written.
8090

91+
The generic host builder will add console-based logger by default, namely `ILoggerFactory` and `ILogger<T>`.
92+
`AddMcpServer` will remove them by default for the same reason as above.
93+
If you still want to keep them, set `keepDefaultLogging` to `true` in `AddMcpServer`.
94+
8195
```csharp
8296
// Using Serilog
8397
.ConfigureLogging(logging => logging.AddSerilog(yourSerilogLogger))
@@ -88,27 +102,25 @@ If no logging provider is configured, a null logger will be used, resulting in n
88102

89103
### Implementing Tools
90104

91-
Tools are implemented as handlers. Here's a simplified example from the calculator demo:
105+
Tools are implemented as handlers.
106+
For NativeAOT compatibility, a `JsonTypeInfo` is required for the parameter type.
107+
Then you can either implement a handler class to enjoy dependency injection etc.,
108+
or supply a function directly.
92109

93-
```csharp
94-
public class CalculatorParameters
95-
{
96-
public required CalculatorOperation Operation { get; init; }
97-
public required double A { get; init; }
98-
public required double B { get; init; }
99-
}
100-
101-
public enum CalculatorOperation { Add, Subtract, Multiply, Divide }
102-
```
110+
More documentation and implementation guide coming soon.
103111

104-
Check out the complete calculator demo for a full working example including:
105112

106-
- Tool handler implementation
107-
- Request/response handling
108-
- Error management
109-
- Logging setup
113+
## Technical Details
110114

111-
More documentation and implementation guide coming soon.
115+
### Architecture
116+
117+
The project is structured into multiple components:
118+
119+
- **Core Library**: Contains the fundamental protocol implementation
120+
- **Server Components**: Handles communication and request processing
121+
- **Server Hosting**: Integrates MCP server to .NET generic host
122+
- **Demo**: Provides working examples
123+
- a calculator application
112124

113125
## Development Status
114126

0 commit comments

Comments
 (0)