Skip to content

Commit 69d6585

Browse files
authored
Merge pull request #14 from codebytes/mcp
Mcp
2 parents b87c67d + 15a3f79 commit 69d6585

49 files changed

Lines changed: 2751 additions & 213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2-
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
31
{
4-
"name": "C# (.NET)",
5-
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/dotnet:1-9.0-bookworm",
7-
"features": {
8-
"ghcr.io/devcontainers/features/azure-cli:1": {},
9-
"ghcr.io/azure/azure-dev/azd:0": {},
10-
"ghcr.io/devcontainers/features/dotnet:2": {
11-
"version": "8.0"
12-
}
13-
}
2+
"name": ".NET Aspire",
3+
// Base .NET 9 image. Alternatively a Dockerfile/compose could be used.
4+
"image": "mcr.microsoft.com/devcontainers/dotnet:9.0-bookworm",
5+
"features": {
6+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
7+
"ghcr.io/devcontainers/features/powershell:1": {},
8+
"ghcr.io/devcontainers/features/azure-cli:1": {},
9+
"ghcr.io/devcontainers/features/github-cli:1": {},
10+
"ghcr.io/devcontainers/features/node:1": {},
11+
"ghcr.io/azure/azure-dev/azd:0": {}
12+
},
1413

15-
// Features to add to the dev container. More info: https://containers.dev/features.
16-
// "features": {},
14+
// Install Aspire tooling & workloads early in create lifecycle.
15+
// (Previous postCreateCommand replaced by onCreateCommand as requested.)
16+
// Former: "postCreateCommand": "dotnet workload install aspire && dotnet restore <project>"
17+
"onCreateCommand": "curl -sSL https://aspire.dev/install.sh | bash",
18+
// Trust HTTPS dev certs on each container start (may be a no-op in headless Linux but harmless).
19+
"postStartCommand": "dotnet dev-certs https --trust || true",
1720

18-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
19-
// "forwardPorts": [5000, 5001],
20-
// "portsAttributes": {
21-
// "5001": {
22-
// "protocol": "https"
23-
// }
24-
// }
25-
26-
// Use 'postCreateCommand' to run commands after the container is created.
27-
// "postCreateCommand": "dotnet restore",
28-
29-
// Configure tool-specific properties.
30-
// "customizations": {},
31-
32-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
33-
// "remoteUser": "root"
34-
}
21+
"customizations": {
22+
"vscode": {
23+
"extensions": [
24+
"ms-dotnettools.csdevkit",
25+
"GitHub.copilot-chat",
26+
"GitHub.copilot"
27+
]
28+
}
29+
},
30+
"forwardPorts": [5087],
31+
"portsAttributes": {
32+
"5087": { "label": "BuildWithAspire.Web", "onAutoForward": "openBrowser" }
33+
},
34+
"remoteUser": "vscode"
35+
}

Copilot-Processing.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build with Aspire
22

3-
This repository contains resources and examples demonstrating building with Aspire.
3+
This repository contains resources and examples demonstrating building with .NET Aspire, including a complete implementation of the Model Context Protocol (MCP) for AI agent tools.
44

55
## Slides
66

@@ -17,10 +17,85 @@ This repository provides insights, best practices, and demonstrations for buildi
1717
- Advanced scenarios like optimizing performance and scalability.
1818
- Publishing Aspire applications to various platforms.
1919
- Passing configuration and secrets to Aspire applications.
20+
- **MCP Server Implementation**: Complete implementation using the official MCP C# SDK with dynamic tool discovery over HTTPS/SSE
21+
22+
## Project Features
23+
24+
### MCP Server Integration
25+
26+
This project demonstrates a production-ready implementation of the Model Context Protocol (MCP):
27+
28+
- **Official MCP C# SDK**: Uses [modelcontextprotocol/csharp-sdk](https://github.com/modelcontextprotocol/csharp-sdk)
29+
- **Dynamic Tool Discovery**: API service discovers tools from MCP server at runtime
30+
- **HTTPS/SSE Transport**: Server-Sent Events for bidirectional communication
31+
- **Service Discovery**: Aspire handles endpoint resolution between services
32+
- **13 Built-in Tools**: Weather, System, and Math tools ready to use
33+
- **Microsoft Agent Framework**: Integrated with AI agent for autonomous tool usage
34+
35+
### Architecture
36+
37+
```
38+
API Service → (HTTPS/SSE) → MCP Server → Tools
39+
↓ ↓
40+
Chat Agent WeatherTools
41+
(Microsoft Agent Framework) SystemTools
42+
MathTools
43+
```
44+
45+
### Documentation
46+
47+
- **[api-tests/](./api-tests/)**: HTTP test files for all endpoints
48+
- **[MCP Server README](./src/BuildWithAspire.MCPServer/README.md)**: MCP Server implementation details
49+
50+
## Getting Started
51+
52+
### Prerequisites
53+
54+
- .NET 9.0 SDK or later
55+
- Docker Desktop (for Aspire)
56+
- Visual Studio Code or Visual Studio 2022
57+
58+
### Quick Start
59+
60+
```bash
61+
# Clone the repository
62+
git clone https://github.com/codebytes/build-with-aspire.git
63+
cd build-with-aspire
64+
65+
# Run with .NET CLI
66+
cd src/BuildWithAspire.AppHost
67+
dotnet run
68+
69+
# Or press F5 in VS Code / Visual Studio
70+
```
71+
72+
The Aspire Dashboard will open at `https://localhost:17020` showing all services.
73+
74+
### Service Endpoints
75+
76+
- **MCP Server**: http://localhost:8080
77+
- **API Service**: http://localhost:5020
78+
- **Aspire Dashboard**: https://localhost:17020
79+
80+
### Testing the MCP Server
81+
82+
```bash
83+
# List available tools
84+
curl http://localhost:5020/mcp/tools
85+
86+
# Check service health
87+
curl http://localhost:8080/health
88+
curl http://localhost:5020/health
89+
```
90+
91+
Use the [api-tests/](./api-tests/) directory for more HTTP test examples.
2092

2193
## Resources
2294

2395
- [.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview)
96+
- [MCP Specification](https://modelcontextprotocol.io/)
97+
- [MCP C# SDK](https://github.com/modelcontextprotocol/csharp-sdk)
98+
- [Microsoft Agent Framework](https://github.com/microsoft/agent-framework)
2499
- [Aspirify](https://aspireify.net/)
25100
- [Aspire Samples](https://github.com/dotnet/aspire-samples)
26101

api-tests/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# API Testing Files
2+
3+
This directory contains HTTP request files for testing all APIs in the BuildWithAspire application.
4+
5+
## Files Overview
6+
7+
- **`apiservice.http`** - Comprehensive tests for the main API service
8+
- **`mcpserver.http`** - Tests for the MCP (Model Context Protocol) server
9+
- **`webfrontend.http`** - Tests for the web frontend endpoints
10+
11+
## How to Use
12+
13+
### 1. Using VS Code REST Client Extension
14+
15+
Install the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension for VS Code.
16+
17+
1. Open any `.http` file
18+
2. Click the "Send Request" button above each request
19+
3. View the response in the new tab
20+
21+
### 2. Update Base URLs
22+
23+
Before testing, update the base URLs in each file to match your current Aspire deployment:
24+
25+
1. Run `aspire run`
26+
2. Check the Aspire dashboard for current port assignments
27+
3. Update the `@baseUrl` variables in each file
28+
29+
Example port assignments (these change on each run):
30+
```
31+
webfrontend: https://localhost:7051
32+
apiservice: https://localhost:7287
33+
mcpserver: http://localhost:34055
34+
```
35+
36+
### 3. Testing Workflows
37+
38+
#### API Service Testing
39+
Use `apiservice.http` for comprehensive API testing:
40+
1. Test weather endpoints
41+
2. Create conversations
42+
3. Send messages
43+
4. Test chat functionality
44+
45+
#### MCP Server Testing
46+
Use `mcpserver.http` to test the weather tools directly.
47+
48+
## API Documentation
49+
50+
### Scalar Documentation (Interactive)
51+
52+
When running in development mode, visit these URLs in your browser:
53+
54+
- **API Service**: `https://localhost:7287/scalar/v1`
55+
- **MCP Server**: `http://localhost:34055/scalar/v1`
56+
57+
### OpenAPI Specifications
58+
59+
- **API Service**: `https://localhost:7287/openapi/v1.json`
60+
- **MCP Server**: `http://localhost:34055/openapi/v1.json`
61+
62+
## Common Test Scenarios
63+
64+
### 1. MCP Tool Testing
65+
```http
66+
# List available MCP tools
67+
GET {{apiService}}/mcp/tools
68+
69+
# Call weather tools via API Service
70+
POST {{apiService}}/mcp/call/GetCurrentWeather
71+
POST {{apiService}}/mcp/call/GetWeatherForecast
72+
73+
# Direct MCP protocol calls to server (JSON-RPC)
74+
POST {{mcpServer}}/mcp
75+
{
76+
"jsonrpc": "2.0",
77+
"id": "1",
78+
"method": "tools/call",
79+
"params": {
80+
"name": "GetCurrentWeather",
81+
"arguments": {}
82+
}
83+
}
84+
```
85+
86+
### 2. Conversation Flow
87+
```http
88+
# 1. Create conversation
89+
POST {{apiService}}/conversations
90+
{
91+
"name": "Test Chat"
92+
}
93+
94+
# 2. Send message (use ID from step 1)
95+
POST {{apiService}}/conversations/{id}/messages
96+
{
97+
"message": "Hello!"
98+
}
99+
100+
# 3. Get conversation history
101+
GET {{apiService}}/conversations/{id}
102+
```
103+
104+
### 3. Health Monitoring
105+
```http
106+
GET {{apiService}}/health
107+
GET {{mcpServer}}/health
108+
GET {{webFrontend}}/health
109+
```
110+
111+
## Troubleshooting
112+
113+
### Port Issues
114+
If requests fail, check that:
115+
1. Aspire is running (`aspire run`)
116+
2. Ports match the Aspire dashboard
117+
3. Services are healthy (green status)
118+
119+
### SSL/TLS Issues
120+
For HTTPS endpoints, you may need to:
121+
1. Accept self-signed certificates in your browser
122+
2. Use HTTP variants if available
123+
3. Check Aspire certificate configuration
124+
125+
### Authentication
126+
Most endpoints don't require authentication in development mode. For production deployments, you may need to add authorization headers.
127+
128+
## Contributing
129+
130+
When adding new endpoints:
131+
1. Add them to the appropriate service file
132+
2. Include proper documentation
133+
3. Add examples with realistic data
134+
4. Update this README if needed

0 commit comments

Comments
 (0)