Skip to content

Implement Model Context Protocol (MCP) integration with Aspire orchestration #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 20, 2025

This PR implements a comprehensive Model Context Protocol (MCP) solution integrated with .NET Aspire, enabling AI models to dynamically discover and use tools through a standardized interface.

What is MCP?

Model Context Protocol (MCP) is a standard that enables:

  • Dynamic Tool Discovery: AI models can discover available tools at runtime
  • Standardized Interface: Consistent API for tool calling across different systems
  • Interoperable Hosting: Tools can be reused across multiple AI applications

Key Features Implemented

🔧 MCP Server (BuildWithAspire.McpServer)

  • Weather Tool: Get forecasts for any location with customizable days (1-7)
  • Time Tool: Current date/time with timezone support and multiple formats
  • REST API: Standardized endpoints for tool discovery (/mcp/tools) and execution (/mcp/tools/call)
  • JSON Schema Validation: Comprehensive parameter validation and error handling

🤖 AI Service Integration

  • Intelligent Message Parsing: Automatically detects weather/time queries in chat
  • MCP Client Service: Seamless communication with MCP server
  • Context Enrichment: AI responses enhanced with real tool data
  • Demo Endpoint: Live demonstration at /mcp/demo

🏗️ Aspire Orchestration

  • Service Discovery: AI service automatically locates MCP server
  • Health Monitoring: Built-in health checks and telemetry
  • Scalable Architecture: Independent scaling of tool servers

✅ Comprehensive Testing

  • 16 Unit Tests: 100% passing test suite covering all functionality
  • Parameter Validation: Tests for JSON deserialization and edge cases
  • Error Scenarios: Comprehensive error handling validation

Usage Examples

Intelligent Chat Integration

# Ask for weather - automatically calls MCP weather tool
POST /conversations/{id}/messages
{"message": "What's the weather like in Tokyo?"}

# Ask for time - automatically calls MCP time tool  
POST /conversations/{id}/messages
{"message": "What time is it in New York?"}

Direct Tool Calls

# Call weather tool directly
POST /mcp/tools/call
{
  "name": "get_weather",
  "arguments": {
    "location": "San Francisco",
    "days": 3
  }
}

# Get available tools
GET /mcp/tools

Benefits Over Traditional APIs

Traditional APIs MCP Integration
❌ Hardcoded endpoints ✅ Dynamic discovery
❌ Manual integration ✅ Standardized interface
❌ Tight coupling ✅ Loose coupling via protocol
❌ Limited reusability ✅ Cross-system compatibility

Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   AI Service    │────│   MCP Server    │────│   Tool Suite    │
│ - Chat Service  │    │ - Tool Registry │    │ - Weather Tool  │
│ - AI Models     │    │ - Request/Resp  │    │ - Time Tool     │
│ - MCP Client    │    │ - Validation    │    │ - Custom Tools  │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         └───────────────────────┼───────────────────────┘
                                 │
                    ┌─────────────────┐
                    │ Aspire AppHost  │
                    │ - Service Disc. │
                    │ - Health Checks │
                    │ - Telemetry     │
                    └─────────────────┘

Documentation

Added comprehensive documentation (MCP_INTEGRATION.md) covering:

  • Detailed architecture explanation
  • Tool development patterns
  • Best practices and security considerations
  • Migration guide from traditional APIs
  • Future enhancement roadmap

Migration Path

The implementation maintains backward compatibility:

  • ✅ Original /weatherforecast endpoint still works
  • ✅ Existing chat functionality preserved
  • ✅ Progressive adoption of MCP tools

This establishes a foundation for building sophisticated AI applications with rich, discoverable tool ecosystems using industry-standard protocols.

Fixes #10.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/search/repositories
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 20, 2025 22:42
Co-authored-by: codebytes <47988+codebytes@users.noreply.github.com>
Co-authored-by: codebytes <47988+codebytes@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Build an MCP Component and Register It with Aspire Implement Model Context Protocol (MCP) integration with Aspire orchestration Jul 20, 2025
@Copilot Copilot AI requested a review from codebytes July 20, 2025 22:53
Copilot finished work on behalf of codebytes July 20, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build an MCP Component and Register It with Aspire
2 participants