Skip to content

Commit 5ddfa1c

Browse files
author
Sandro Lange
committed
feat: adds McpServer SSE edition - you'll now be able to use the McpTools with a much larger variety of client tools
1 parent 0f9633c commit 5ddfa1c

File tree

14 files changed

+195
-18
lines changed

14 files changed

+195
-18
lines changed

ExportPaperless.McpServer/DataContracts/ExportByQueryDto.cs renamed to ExportPaperless.Mcp/DataContracts/ExportByQueryDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Runtime.Serialization;
22

3-
namespace ExportPaperless.McpServer.DataContracts;
3+
namespace ExportPaperless.Mcp.DataContracts;
44

55
[DataContract]
66
public class ExportByQueryDto
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="ModelContextProtocol" Version="0.2.0-preview.1"/>
11+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
12+
<PackageReference Include="Serilog" Version="4.3.0" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\ExportPaperless.Domain\ExportPaperless.Domain.csproj"/>
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using ExportPaperless.Domain.Services;
2+
using ExportPaperless.Mcp.Services;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace ExportPaperless.Mcp;
7+
8+
public static class ServiceCollectionExtensions
9+
{
10+
public static void AddMcp(this IServiceCollection services, IConfiguration configuration)
11+
{
12+
var mcpConfigurationService = new McpConfigurationService(configuration);
13+
services.AddTransient<IMcpConfigurationService, McpConfigurationService>(b => mcpConfigurationService);
14+
services.AddSingleton(_ =>
15+
{
16+
var httpClient = new HttpClient { BaseAddress = mcpConfigurationService.ExportPaperlessApiUrl };
17+
if (!string.IsNullOrEmpty(mcpConfigurationService.ExportPaperlessApiToken))
18+
{
19+
httpClient.DefaultRequestHeaders.Add("x-api-key", mcpConfigurationService.ExportPaperlessApiToken);
20+
}
21+
22+
return httpClient;
23+
});
24+
25+
}
26+
}

ExportPaperless.McpServer/Services/McpConfigurationService.cs renamed to ExportPaperless.Mcp/Services/McpConfigurationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ExportPaperless.Domain.Services;
22
using Microsoft.Extensions.Configuration;
33

4-
namespace ExportPaperless.McpServer.Services;
4+
namespace ExportPaperless.Mcp.Services;
55

66
public class McpConfigurationService(IConfiguration configuration): IMcpConfigurationService
77
{

ExportPaperless.McpServer/Tools/ExportFromPaperlessTools.cs renamed to ExportPaperless.Mcp/Tools/ExportFromPaperlessTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel;
22
using System.Net.Http.Json;
3-
using System.Runtime.Serialization;
43
using System.Text.Json;
4+
using ExportPaperless.Mcp.DataContracts;
55
using ExportPaperless.McpServer.DataContracts;
66
using Microsoft.Extensions.AI;
77
using ModelContextProtocol.Server;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.13"/>
11+
<PackageReference Include="ModelContextProtocol.AspNetCore" Version="0.2.0-preview.1" />
12+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
13+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
14+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
15+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
16+
<PackageReference Include="Serilog" Version="4.3.0" />
17+
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
18+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
19+
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
20+
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
21+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
22+
<PackageReference Include="ModelContextProtocol" Version="0.2.0-preview.1" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\ExportPaperless.Mcp\ExportPaperless.Mcp.csproj" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using ExportPaperless.Domain;
2+
using ExportPaperless.Mcp;
3+
using ExportPaperless.McpServer.Tools;
4+
using OpenTelemetry;
5+
using OpenTelemetry.Metrics;
6+
using OpenTelemetry.Trace;
7+
using Serilog;
8+
9+
Log.Logger = new LoggerConfiguration()
10+
.MinimumLevel.Verbose() // Capture all log levels
11+
.WriteTo.File(Path.Combine("/tmp", "logs", "ExportPaperless_McpServer_SSE_.log"),
12+
rollingInterval: RollingInterval.Day,
13+
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
14+
.WriteTo.Debug()
15+
.WriteTo.Console(standardErrorFromLevel: Serilog.Events.LogEventLevel.Verbose)
16+
.CreateLogger();
17+
18+
var builder = WebApplication.CreateBuilder(args);
19+
20+
builder.Services.AddSerilog();
21+
var configuration = Configuration.GetStandardConfiguration();
22+
builder.Services.AddSingleton(configuration);
23+
builder.Services.AddMcp(configuration);
24+
25+
builder.Services.AddMcpServer()
26+
.WithHttpTransport()
27+
.WithToolsFromAssembly(typeof(ExportFromPaperlessTools).Assembly);
28+
29+
builder.Services.AddOpenTelemetry()
30+
.WithTracing(b => b.AddSource("*")
31+
.AddAspNetCoreInstrumentation()
32+
.AddHttpClientInstrumentation())
33+
.WithMetrics(b => b.AddMeter("*")
34+
.AddAspNetCoreInstrumentation()
35+
.AddHttpClientInstrumentation())
36+
.WithLogging()
37+
.UseOtlpExporter();
38+
39+
var app = builder.Build();
40+
41+
app.MapMcp();
42+
43+
app.Run();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:12610",
8+
"sslPort": 44351
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5253",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
"launchUrl": "swagger",
27+
"applicationUrl": "https://localhost:7112;http://localhost:5253",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "swagger",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)