1+ //Minimal API approach
2+ using AbeckDev . DbTimetable . Mcp . Models ;
3+ using AbeckDev . DbTimetable . Mcp . Services ;
4+ using ModelContextProtocol . Protocol ;
5+
6+ var builder = WebApplication . CreateBuilder ( args ) ;
7+
8+ //Setup Config provider
9+ builder . Configuration
10+ . SetBasePath ( Directory . GetCurrentDirectory ( ) )
11+ . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
12+ . AddJsonFile ( $ "appsettings.{ builder . Environment . EnvironmentName } .json", optional : true )
13+ . AddEnvironmentVariables ( ) ;
14+
15+ builder . Services . Configure < Configuration > (
16+ builder . Configuration . GetSection ( Configuration . SectionName ) ) ;
17+
18+ var dbConfig = builder . Configuration
19+ . GetSection ( Configuration . SectionName )
20+ . Get < Configuration > ( ) ?? new Configuration ( ) ;
21+
22+ builder . Services . AddHttpClient < TimeTableService > ( client =>
23+ {
24+ client . BaseAddress = new Uri ( dbConfig . BaseUrl ) ;
25+ client . DefaultRequestHeaders . Accept . Add (
26+ new System . Net . Http . Headers . MediaTypeWithQualityHeaderValue ( "application/xml" ) ) ;
27+ client . Timeout = TimeSpan . FromSeconds ( 30 ) ;
28+ } ) ;
29+
30+ // Add services to the container.
31+ // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
32+ builder . Services . AddMcpServer ( options =>
33+ {
34+ options . ServerInfo = new Implementation { Name = "Deutsche Bahn - Timetable API" , Version = "1.0.0" } ;
35+ } )
36+ . WithHttpTransport ( )
37+ . WithToolsFromAssembly ( )
38+ . WithPromptsFromAssembly ( ) ;
39+
40+
41+ var app = builder . Build ( ) ;
42+
43+ app . MapMcp ( "/mcp" ) ;
44+
45+ app . Run ( "http://0.0.0.0:3001" ) ;
0 commit comments