Showing posts with label ai. Show all posts
Showing posts with label ai. Show all posts

How to Have GitLab CI/CD for a .NET Aspire Project

Getting a complete CI/CD pipeline for your .NET Aspire solution doesn't have to be complicated. I've created a template that gives you everything you need to get started in minutes.

(blog post en français ici)

Watch the Video


Part 1: The Ready-to-Use Template

I've built a .NET Aspire template that comes with everything configured and ready to go. Here's what you get:

What's Included

  • A classic .NET Aspire Starter project (API and frontend)
  • Unit tests using xUnit (easily adaptable to other testing frameworks)
  • Complete .gitlab-ci.yml pipeline configuration
  • Security scanning and secret detection
  • All documentation you need

What the Pipeline Does

The pipeline runs two main jobs automatically:

  1. Build: Compiles your code
  2. Test: Runs all unit tests, scans for vulnerabilities, and checks for accidentally committed secrets (API keys, passwords, etc.)

You can see all test results directly in GitLab's interface, making it easy to track your project's health.

How to Get Started

It's simple:

  1. Clone the template repository: cloud5mins/aspire-template
  2. Replace the sample project with your own .NET Aspire code
  3. Push to your GitLab repository
  4. Watch your CI/CD pipeline run automatically

That's it! You immediately get automated builds, testing, and security scanning.

Pro Tip: The best time to set up CI/CD is when you're just starting your project because everything is still simple.


Part 2: Building the Template with GitLab Duo

Now let me share my experience creating this template using GitLab's AI assistant, GitLab Duo.

Starting Simple, Growing Smart

I didn't build this complex pipeline all at once. I started with something very basic and used GitLab Duo to gradually add features. The AI helped me:

  • Add secret detection when I asked: "How can I scan for accidentally committed secrets?"
  • Fix test execution issues when my unit tests weren't running properly
  • Optimize the pipeline structure for better performance
screen capture in VSCode using GitLab Duo to change the default location for the job SAST

Working with GitLab in VS Code

While you can edit .gitlab-ci.yml files directly in GitLab's web interface, I prefer VS Code. Here's my setup:

  1. Install the official GitLab extension from the VS Code marketplace

Once you've signed in, this extension gives you:

  • Direct access to GitLab issues and work items
  • AI-powered chat with GitLab Duo

GitLab Duo in Action

GitLab Duo became my pair programming partner. Here's how I used it:

Understanding Code: I could type /explain and ask Duo to explain what any part of my pipeline configuration does by highlighting that section.

screen capture in VSCode using GitLab Duo to explain part of the code

Solving Problems: When my solution didn't compile, I described the issue to Duo and got specific suggestions. For example, it helped me realize some projects weren't in .NET 9 because dotnet build required the Aspire workload. I could either keep my project in .NET 8 and add a before_script instruction to install the workload or upgrade to .NET 9; I picked the latest.

Adding Features: I started with just build and test, then incrementally asked Duo to help me add security scanning, secret detection, and better error handling.

Adding Context: Using /include to add the project file or the .gitlab-ci.yml file while asking questions helped Duo understand the context better.

Learn More with the Docs: During my journey, I knew Duo wasn't just making things up as it was referencing the documentation. I could continue my learning there and read more examples of how before_script is used in different contexts.

The AI-Assisted Development Experience

What impressed me most was how GitLab Duo helped me learn while building. Instead of just copying configurations from documentation, each conversation taught me something new about GitLab CI/CD best practices.

Conclusion

I think this template can be useful for anyone starting a .NET Aspire project. Ready to try it? Clone the template at cloud5mins/aspire-template and start building with confidence.

Whether you're new to .NET Aspire or CI/CD, this template gives you a good foundation. And if you want to customize it further, GitLab Duo is there to help you understand and modify the configuration.

If you think we should add more features or improve the template, feel free to open an issue in the repository. Your feedback is always welcome!

[Screen capture of the Aspire template project on GitLab




Thanks to ‪David Fowler‬ for his feedback!

How to convert code with GitHub Copilot, can AI really help?

Recently, someone asked me an interesting question: "Can GitHub Copilot or AI help me convert an application from one language to another?" My answer was a definitive yes! AI can not only help you write code in a new language, but it can also improve team collaboration and bridge the knowledge gap between developers who know different programming languages.

(Version française ici)

Setting Up the Environment

To demonstrate this capability, I decided to convert a COBOL application to Java—a perfect test case since I don't know either language well, which means I really needed Copilot to do the heavy lifting. All the code is available on GitHub.

The first step was setting up a proper development environment. I used a dev container and asked Copilot to help me build it. I also asked for recommendations on the best VS Code extensions for Java development. Within just a few minutes, I had a fully configured environment ready for Java development.

Choosing the Right Copilot Agent

When working with GitHub Copilot for code conversion, you have different mode to choose from:

  • Ask: Great for general questions (like asking about Java extensions)
  • Edit: Perfect for simple document editing (like modifying the generated code)
  • Agent: The powerhouse for complex tasks involving multiple files, imports, and structural changes

For code conversion projects, the Agent is your best friend. It can look at different source files, understand project structure, edit code, and even create new files on your behalf.

The Conversion Process

I used Claude 3.5 Sonnet for this conversion. Here's the simple prompt I used:

"Convert this hello business COBOL application into Java"

Copilot didn't just convert the code, it also provided detailed information about how to execute the Java application, which was invaluable since I had no Java experience.

The results varied depending on the AI model used (Claude, GPT, Gemini, etc.), but the core functionality remained consistent across different attempts. Since the original application was simple, I converted it multiple times using different prompts and models to test the consistency. Sometimes it generated a single file, other times it created multiple files: a main application and an Employee class (which wasn't in my original COBOL version). Sometimes it updated the Makefile to allow compilation and execution using make, while other times it provided instructions to use javac and java commands directly.

This variability is expected with generative AI results will differ between runs, but the core functionality remains reliable.

Real-World Challenges

Of course, the conversion wasn't perfect on the first try. For example, I encountered runtime errors when executing the application. The issue was with the data format—the original file used a flat file format with fixed length records (19 characters per record) and no line breaks.

I went back to Copilot, highlighted the error message from the terminal, and provided additional context about the 19 character record format. This iterative approach is key to successful AI assisted conversion.

"It's not working as expected, check the error in #terminalSelection. The records have fixed length of 19 characters without line breaks. Adjust the code to handle this format"

The Results

After the iterative improvements, my Java application successfully:

  • Compiled without errors
  • Processed all employee records
  • Generated a report with employee data
  • Calculated total salary (a nice addition that wasn't in the original)

While the output format wasn't identical to the original COBOL version (missing leading zeros, different line spacing), the core functionality was preserved.

Video Demonstration

Watch the complete conversion process in action:

Best Practices for AI-Assisted Code Conversion

Based on this experience, here are my recommendations:

1. Start with Small Pieces

Don't try to convert thousands of lines at once. Break your conversion into manageable modules or functions.

2. Set Up Project Standards

Consider creating a .github folder at your project root with an instructions.md file containing:

  • Best practices for your target language
  • Patterns and tools to use
  • Specific versions and frameworks
  • Enterprise standards to follow

3. Stay Involved in the Process

You're not just a spectator - you're an active participant. Review the changes, test the output, and provide feedback when things don't work as expected.

4. Iterate and Improve

Don't expect perfection on the first try. In my case, the converted application worked but produced slightly different output formatting. This is normal and expected, after all you are converting between two different languages with different conventions and styles.

Can AI Really Help with Code Conversion?

Absolutely, yes! GitHub Copilot can significantly:

  • Speed up the conversion process
  • Help with syntax and language specific patterns
  • Provide guidance on running and compiling the target language
  • Bridge knowledge gaps between team members
  • Generate supporting files and documentation

However, remember that it's generative AI, results will vary between runs, and you shouldn't expect identical output every time.

Final Thoughts

GitHub Copilot is definitely a tool you need in your toolkit for conversion projects. It won't replace the need for human oversight and testing, but it will dramatically accelerate the process and help teams collaborate more effectively across different programming languages.

The key is to approach it as a collaborative process where AI does the heavy lifting while you provide guidance, context, and quality assurance. Start small, iterate often, and don't be afraid to ask for clarification or corrections when the output isn't quite right.

Have you tried using AI for code conversion? I'd love to hear about your experiences in the comments below! Visit c5m.ca/copilot to get started with GitHub Copilot.

References


Reading Notes #654

Welcome to another edition of my reading notes! This week, I’ve gathered a selection of insightful articles and resources covering topics like AI, cloud security, open source, and developer productivity. Whether you’re interested in best practices, new tools, or thought-provoking perspectives, there’s something here for everyone. 

Dive in and enjoy the highlights!

Suggestion of the week

  • Copilot, The Good Parts: Efficiency (Rob Conery) - I love that post, it's so true! There are good and bad ways to use any tools. And I personally would really like seeing Rob build his stuff. Let's him know If you think like me.

Programming

Open Source

Databases

Miscellaneous


~frank


Reading Notes #653

Welcome to Reading Notes #653 another packed edition of insights, tools, and updates from the tech world! This week's roundup dives into legendary engineering wisdom, AI controversies, and the latest innovations in Docker, Azure, and VS Code. Whether you're exploring MCP, refining your scripting skills, or gearing up for the newest Azure Developer CLI release, there's something here for every developer.

windmill on the cap of Ile Perrot

Let’s get into it!

Cloud

  • Azure Developer CLI (azd) - June 2025 (Kristen Womack) - Love that tool, great updates, so many new features and improvements in this version, very looking forward to try all of them, turning them all

AI

Programming

Miscellaneous


~frank

Stop Writing Git Commits: How AI-Powered GitKraken CLI Accelerates Your Development

As developers, we're constantly looking for tools that can help us stay in the flow and be more productive. Today, I want to share a powerful tool that's been gaining traction in the developer community: GitKraken CLI. This command-line interface brings together several key features that modern developers love - it's AI-powered, terminal-based, and incredibly efficient for managing Git workflows.

(Version française ici)

What Makes GitKraken CLI Special?

GitKraken CLI (accessible via the gk command) stands out because it simplifies complex Git workflows while adding intelligent automation. Unlike traditional Git commands, it provides a more intuitive workflow management system that can handle multiple repositories simultaneously.

Getting Started

Installation is straightforward. On Windows, you can install it using:

winget install gitkraken.cli

Once installed, you'll have access to the gk command, which becomes your gateway to streamlined Git operations.

The Workflow in Action

Let's walk through a typical development session using GitKraken CLI:

1. Starting a Work Session

Instead of manually creating branches and switching contexts, you can start a focused work session:

gk w start "Add Behind my Cloud feed" -i "Add Behind my Cloud feed #1"

This single command:

  • Creates a new branch based on your issue/feature name
  • Switches to that branch automatically
  • Links the work session to a specific issue
  • Sets up your development environment for focused work

2. Managing Multiple Work Sessions

You can easily see all your active work sessions:

gk w list

This is particularly powerful when working across multiple repositories or juggling several features simultaneously.

3. Committing with Intelligence

After making your changes, adding files works as expected:

gk add .

But here's where the AI magic happens. Instead of writing commit messages manually:

gk w commit --ai

The AI analyzes your changes and generates meaningful, descriptive commit messages automatically. No more "quick fix" or "update stuff" commits!

4. Pushing and Creating Pull Requests

Publishing your work is equally streamlined:

gk w push

And when you're ready to create a pull request:

gk w pr create --ai

Again, AI assistance helps generate appropriate PR titles and descriptions based on your work.

5. Wrapping Up

Once your work is complete and merged, clean up is simple:

gk w end

This command:

  • Switches you back to the main branch
  • Deletes the feature branch, locally and on GitHub
  • Closes the work session
  • Leaves your repository clean and ready for the next task
all the commands


Why This Matters

The beauty of GitKraken CLI lies in its ability to keep you in the zone. You don't need to:

  • Switch between multiple tools
  • Remember complex Git commands
  • Write commit messages from scratch
  • Manually manage branch lifecycle

Everything flows naturally from one command to the next, maintaining your focus on what matters most: writing code.

Multi-Repository Power

One of the standout features is GitKraken CLI's ability to manage multiple repositories simultaneously. This is invaluable for:

  • Microservices architectures
  • Full-stack applications with separate frontend/backend repos
  • Organizations with multiple related projects

Try It Yourself

GitKraken CLI is part of a broader suite of developer tools that GitKraken offers. The CLI itself is free to use, which makes it easy to experiment with and integrate into your workflow without any upfront commitment. If you find value in the CLI and want to explore their other tools, GitKraken has various products that might complement your development setup.

The learning curve is genuinely minimal since it builds on Git concepts you already know while adding helpful automation. I've found that even small workflow improvements can compound over time, especially when you're working on multiple projects or dealing with frequent context switching.

If you're curious about what else GitKraken offers beyond the CLI, you can explore their full product lineup here. For those who decide the Pro features would benefit their workflow, as an ambassador of GitKraken I can share my code to provide a 50% discount for your GitKraken Pro subscription.

The combination of AI assistance and intuitive commands addresses real pain points that many developers face daily. Whether GitKraken CLI becomes a core part of your toolkit will depend on your specific workflow, but it's worth trying given that it's free and takes just a few minutes to set up.



The best tools are the ones that get out of your way and let you focus on building. GitKraken CLI aims to do exactly that.

Reading Notes #652

This week, we explore a variety of topics, from database containerization and AI security risks to the evolving landscape of gaming devices and cloud technologies. We also explore the shift towards security-first development and the integration of .NET Aspire with SQL Server for integration testing.


Let's dive in!

Suggestion of the week

Cloud

Programming

Databases

Miscellaneous

~frank

I Co-Wrote 88 Unit Tests Using AI: A Developer's Journey

Testing has always been one of those tasks that developers know is essential but often find tedious. When I decided to add comprehensive unit tests to my NoteBookmark project, I thought: why not make this an experiment in AI-assisted development? What followed was a fascinating 4-hour journey that resulted in 88 unit tests, a complete CI/CD pipeline, and some valuable insights about working with AI coding assistants.

(Version française ici)

The Project: NoteBookmark

NoteBookmark is a .NET application built with C# that helps users manage and organize their reading notes and bookmarks. The project includes an API, a Blazor frontend, and uses Azure services for storage. You can check out the complete project on GitHub.

The Challenge: Starting from Zero

I'll be honest - it had been a while since I'd written comprehensive unit tests. Rather than diving in myself, I decided to see how different AI models would approach this task. My initial request was deliberately vague: "add a test project" without any other specifications.

Looking back, I realize I should have been more specific about which parts of the code I wanted covered. This would have made the review process easier and given me better control over the scope. But sometimes, the best learning comes from letting the AI surprise you.

The Great AI Model Comparison



GPT-4.1: Competent but Quiet

GPT-4.1 delivered decent results, but the experience felt somewhat mechanical. The code it generated was functional, but I found myself wanting more context. The explanations were minimal, and I often had to ask follow-up questions to understand the reasoning behind certain test approaches.

Gemini: The False Start

My experience with Gemini was... strange. Perhaps it was a glitch or an off day, but most of what was generated simply didn't work. I didn't persist with this model for long, as debugging AI-generated code that fundamentally doesn't function defeats the purpose of the exercise. Note that at the time of this writing, Gemini was still in preview, so I expect it to improve over time.

Claude Sonnet: The Clear Winner

This is where the magic happened. Claude Sonnet became my co-pilot of choice for this project. What set it apart wasn't just the quality of the code (though that was excellent), but the quality of the conversation. It felt like having a thoughtful colleague thinking out loud with me.

The explanations were clear and educational. When Claude suggested a particular testing approach, it would explain why. When it encountered a complex scenario, it would walk through its reasoning. I tried different versions of Claude Sonnet but didn't notice significant differences in results - they were all consistently good.

The Development Process: A 4-Hour Journey


Hour 1-2: Getting to Compilation

The first iteration couldn't compile. This wasn't surprising given the complexity of the codebase and the vague initial request. But here's where the AI collaboration really shined. Instead of manually debugging everything myself, I worked with Copilot to identify and fix issues iteratively.

We went through several rounds of:

  1. Identify compilation errors
  2. Discuss the best approach to fix them
  3. Let the AI implement the fixes
  4. Review and refine

After about 2 hours, we had a test project with 88 unit tests that compiled successfully. The AI had chosen xUnit as the testing framework, which I was happy with - it's a solid choice that I might not have picked myself if I was rusty on the current .NET testing landscape.

Hour 2.5-3.5: Making Tests Pass

Getting the tests to compile was one thing; getting them to pass was another challenge entirely. This phase taught me a lot about both my codebase and xUnit features I wasn't familiar with.

I relied heavily on the /explain feature during this phase. When tests failed, I'd ask Claude to explain what was happening and why. This was invaluable for understanding not just the immediate fix, but the underlying testing concepts.

One of those moment was learning about [InlineData(true)] and other xUnit data attributes. These weren't features I was familiar with, and having them explained in context made them immediately useful.


InlineData in the code


Hour 3.5-4: Structure and Style

Once all tests were passing, I spent time ensuring I understood each test and requesting structural changes to match my preferences. This phase was crucial for taking ownership of the code. Just because AI wrote it doesn't mean it should remain a black box. Let's repeat this: Understanding the code is essential; just because AI wrote it doesn't mean it's good.

Beyond Testing: CI/CD Integration

With the tests complete, I asked Copilot to create a GitHub Actions workflow to run tests on every push to main and v-next branches, plus PR reviews. Initially it started modifiying my existing workflow that takess care of the Azure deployment. I wanted a separate workflow for testing, so I interrupted (that's nice I wasn't "forced" to wait), and asked it to create a new one instead. The result was the running-unit-tests.yml workflow that worked perfectly on the first try.

This was genuinely surprising. CI/CD configurations often require tweaking, but the generated workflow handled:

  • Multi-version .NET setup
  • Dependency restoration
  • Building and testing
  • Test result reporting
  • Code coverage analysis
  • Artifact uploading

Code coverage


The PR Enhancement Adventure

Here's where things got interesting. When I asked Copilot to enhance the workflow to show test results in PRs, it started adding components, then paused and asked if it could delete the current version and start from scratch.

I said yes, and I'm glad I did. The rebuilt version created beautiful PR comments showing:

  • Test results summary
  • Code coverage reports (which I didn't ask for but appreciated)
  • Detailed breakdowns.

PR display


The Finishing Touches

No project is complete without proper status indicators. I added a test status badge to the README, giving anyone visiting the repository immediate visibility into the project's health.

test status badge


Key Takeaways


What Worked Well

  1. AI as a Learning Partner: Having Copilot explain testing concepts and xUnit features was like having a patient teacher
  2. Iterative Refinement: The back-and-forth process felt natural and productive
  3. Comprehensive Solutions: The AI didn't just write tests; it created a complete testing infrastructure
  4. Quality Over Speed: While it took 4 hours, the result was thorough and well-structured

What I'd Do Differently

  1. Be More Specific Initially: Starting with clearer scope would have streamlined the process
  2. Set Testing Priorities: Identifying critical paths first would have been valuable
  3. Plan for Visual Test Reports: Thinking about test result visualization from the start

Lessons About AI Collaboration

  • Model Choice Matters: The difference between AI models was significant
  • Conversation Quality Matters: Clear explanations make the collaboration more valuable
  • Trust but Verify: Understanding every piece of generated code is crucial
  • Embrace Iteration: The best results come from multiple refinement cycles

The Bigger Picture

This experiment reinforced my belief that AI coding assistants are most powerful when they're true collaborators rather than code generators. The value wasn't just in the 88 tests that were written, but in the learning that happened along the way.

For developers hesitant about AI assistance in testing: this isn't about replacing your testing skills, it's about augmenting them. The AI handles the boilerplate and suggests patterns, but you bring the domain knowledge and quality judgment.

Conclusion

Would I do this again? Absolutely. The combination of comprehensive test coverage, learning opportunities, and time efficiency made this a clear win. The 4 hours invested created not just tests, but a complete testing infrastructure that will pay dividends throughout the project's lifecycle.

If you're considering AI-assisted testing for your own projects, my advice is simple: start the conversation, be prepared to iterate, and don't be afraid to ask "why" at every step. The goal isn't just working code - it's understanding and owning that code.

The complete test suite and CI/CD pipeline are available in the NoteBookmark repository if you want to see the results of this AI collaboration in action.


Reading Notes #651

Welcome to another edition of my reading notes! This week brings some fascinating insights into AI's real-world impact, exciting developments in .NET and containerization, plus practical tools for improving our development workflows. 
A duck in a city fontain

From local AI-powered code reviews to Docker security hardening and the upcoming .NET 10 features, there's plenty to explore.

 

AI

Programming

Cloud

Miscellaneous

  • Enhance productivity with AI + Remote Dev (Brigit Murtaugh, Christof Marti, Josh Spicer, Olivia Guzzardo McVicker) - I love the dev container environments, they are so useful! And I also use the remote one when I'm not on my dev device so easy. Happy to see that Copilot will be right there with me.
~frank

Reading Notes #650

It's time for another edition of Reading Notes! This week brings exciting developments in the open source world, with major announcements from Microsoft making WSL and VS Code's AI features open source. We've also got updates on Azure Container Apps, .NET Aspire, and some great insights on developer productivity tools.
 
Let's dive into these interesting reads that caught my attention this week.

Cloud

Programming

Open Source

AI

  • Agent mode for every developer (Katie Savage) - Great new for everyone as the agent mode become available in so many different editor. This post also contains videos to shows some scenarios.

Podcasts

Miscellaneous

  • The experience is enough (Salma Alam-Naylor) - Whether we like it or not, we are people creature. We all need to stop hiding behind our screens and get out there!

~frank

Reading Notes #649

Welcome to another edition of my reading notes! This week I've come across some interesting articles spanning from programming decisions to career tips and AI innovations. Hope you find something valuable in this collection.
minimal photography of a point of land in sandwich between gray sky and water

Programming


AI


Miscellaneous

  • Thriving After a Layoff: The First 30 Days (scrappy girl project) - A friend of mine shared with me this post, and I think it will help me in the upcoming days. So here I am sharing so more can benefit from it

Book cover: The Let Them Theory

Books

  • The Let Them Theory (Mel Robbins) - Stop wasting energy on things you can’t control. It something we all know, but probably forgot the power if it. Let go is hard, but it works in so many scenario. In this book Mel explains how to make it works, and how to use it with a let me action.
     

Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank


Reading Notes #648

Welcome to this week's reading notes! Dive into the latest on Microsoft's new AI chat template, explore Docker's MCP CLI, learn about integrating AI into .NET applications, and discover how to automate .NET MAUI library publishing with GitHub Actions. 

Whether you're interested in AI advancements, programming techniques, or DevOps practices, there's something valuable waiting for you below.

MsDevMtl Meetup - Uno
MsDevMtl Meetup - Uno


Suggestion of the week

  • Exploring the new AI chat template (Andrew Lock) - This new .NET template looks pretty useful and has a lot of components already baked in. This post explains those and shows how to customize it for our usage.

Programming


DevOps


AI


Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank


Reading Notes #647


This post is a collection of my latest reading notes, highlighting interesting articles and resources on AI, programming, databases, and more. Each link includes a brief summary of what I found valuable or noteworthy.
screenshot linux shutdown operations

AI


Programming


Databases


Miscellaneous

  • Help yourself to thrive (Salma) - The human body is an extraordinary machine, extremely strong and conciliant, but it also requires a fine turning. Great post, we must learn from it.


Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank

Reading Notes #646

Welcome to this week's collection of fascinating reads across cloud computing, AI, and programming! As technology continues to evolve at breakneck speed, I've gathered some of the most insightful articles that caught my attention. From securing MCP servers to exploring Rust, there's something here for every tech enthusiast. 
Dive in and discover what's new in our rapidly changing digital landscape.

Cloud

AI

Programming

Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank

Reading Notes #645

Welcome to this week's reading notes! I've found some great articles that caught my eye - from security tips for MCP servers to exciting updates in Rust and AI. Whether you're into cloud services, programming tools, or wondering about the future of coding with AI, there's something here for you.

Let's dive in!

 

Programming

  • The Aspire Compiler (David Fowler) - I really appreciate Aspire. It's one of the tools that completely changed my experience as a developer. Learning more about it is, without a doubt, interesting.

  • Verifying tricky git rebases with git range-diff (Andrew Lock) - Is it possible to really master Git? There is always something new to learn. Nice post going deep.

  • Azure SDK for Rust Goes Beta (Nikos Vaggalis ) - Great news for the Rust developer, this is an important milestone.

AI



Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank


Making AI smarter with an MCP server that manages short URLs

Have you ever wanted to give your AI assistants access to your own custom tools and data? That's exactly what Model Context Protocol (MCP) allows us to do, and I've been experimenting with it lately.

(Version française ici)

I read a lot recently about Model Context Protocol (MCP) and how it is changing the way AI interacts with external systems. I was curious to see how it works and how I can use it in my own projects. There are many tutorial available online but one of my favorite was written by James Montemagno Build a Model Context Protocol (MCP) server in C#. This post isn't a tutorial, but rather a summary of my experience and what I learned along the way while building a real MCP server that manages short URLs.

MCP doesn't change AI itself, it's a protocol that helps your AI model to interact with external resources: API, databases, etc. The protocol simplifies the way AI can access an external system, and it allows the AI to discover the available tools from those resources. Recently I was working on a project that manages short URLs, and I thought it would be a great opportunity to build an MCP server that manages short URLs. I wanted to see how easy it is to build and then use it in VSCode with GitHub Copilot Chat.

Code: All the code of this post is available in the branch exp/mcp-server of the AzUrlShortener repo on GitHub.

Setting Up: Adding an MCP Server to a .NET Aspire Solution

The AzUrlShortener is a web solution that uses .NET Aspire, so the first thing I did was create a new project using the command:

dotnet new web -n Cloud5mins.ShortenerTools.MCPServer -o ./mcpserver

Required Dependencies

To transform this into an MCP server, I added these essential NuGet packages:

  • Microsoft.Extensions.Hosting
  • ModelContextProtocol.AspNetCore

Since this project is part of a .NET Aspire solution, I also added references to:

  • The ServiceDefaults project (for consistent service configuration)
  • The ShortenerTools.Core project (where the business logic lives)

Integrating with Aspire

Next, I needed to integrate the MCP server into the AppHost project, which defines all services in our solution. Here's how I added it to the existing services:

var manAPI = builder.AddProject<Projects.Cloud5mins_ShortenerTools_Api>("api")
						.WithReference(strTables)
						.WaitFor(strTables)
						.WithEnvironment("CustomDomain",customDomain)
						.WithEnvironment("DefaultRedirectUrl",defaultRedirectUrl);

builder.AddProject<Projects.Cloud5mins_ShortenerTools_TinyBlazorAdmin>("admin")
		.WithExternalHttpEndpoints()
		.WithReference(manAPI);

// 👇👇👇 new code for MCP Server
builder.AddProject<Projects.Cloud5mins_ShortenerTools_MCPServer>("mcp")
		.WithReference(manAPI)
		.WithExternalHttpEndpoints();

Notice how I added the MCP server with a reference to the manAPI - this is crucial as it needs access to the URL management API.

Configuring the MCP Server

To complete the setup, I needed to configure the dependency injection in the program.cs file of the MCPServer project. The key part was specifying the BaseAddress of the httpClient:

var builder = WebApplication.CreateBuilder(args);       
builder.Logging.AddConsole(consoleLogOptions =>
{
    // Configure all logs to go to stderr
    consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services.AddMcpServer()
    .WithTools<UrlShortenerTool>();

builder.AddServiceDefaults();

builder.Services.AddHttpClient<UrlManagerClient>(client => 
            {
                client.BaseAddress = new Uri("https+http://api");
            });
            
var app = builder.Build();

app.MapMcp();

app.Run();

That's all that was needed! Thanks to .NET Aspire, integrating the MCP server was straightforward. When you run the solution, the MCP server starts alongside other projects and will be available at http://localhost:{some port}/sse. The /sse part of the endpoint means (Server-Sent Events) and is critical - it's the URL that AI assistants will use to discover available tools.

Implementing the MCP Server Tools

Looking at the code above, two key lines make everything work:

  1. builder.Services.AddMcpServer().WithTools<UrlShortenerTool>(); - registers the MCP server and specifies which tools will be available
  2. app.MapMcp(); - maps the MCP server to the ASP.NET Core pipeline

Defining Tools with Attributes

The UrlShortenerTool class contains all the methods that will be exposed to AI assistants. Let's examine the ListUrl method:

[McpServerTool, Description("Provide a list of all short URLs.")]
public List<ShortUrlEntity> ListUrl()
{
	var urlList = _urlManager.GetUrls().Result.ToList<ShortUrlEntity>();
	return urlList;
}

The [McpServerTool] attribute marks this method as a tool the AI can use. I prefer keeping tool definitions simple, delegating the actual implementation to the UrlManager class that's injected in the constructor: UrlShortenerTool(UrlManagerClient urlManager).

The URL Manager Client

The UrlManagerClient follows standard HttpClient patterns. It receives the pre-configured httpClient in its constructor and uses it to communicate with the API:

public class UrlManagerClient(HttpClient httpClient)
{
	public async Task<IQueryable<ShortUrlEntity>?> GetUrls()
    {
		IQueryable<ShortUrlEntity> urlList = null;
		try{
			using var response = await httpClient.GetAsync("/api/UrlList");
			if(response.IsSuccessStatusCode){
				var urls = await response.Content.ReadFromJsonAsync<ListResponse>();
				urlList = urls!.UrlList.AsQueryable<ShortUrlEntity>();
			}
		}
		catch(Exception ex){
			Console.WriteLine(ex.Message);
		}
        
		return urlList;
    }

	// other methods to manage short URLs
}

This separation of concerns keeps the code clean - tools handle the MCP interface, while the client handles the API communication.

Using the MCP Server with GitHub Copilot Chat

Now for the exciting part - connecting your MCP server to GitHub Copilot Chat! This is where you'll see your custom tools in action.

Configuring Copilot to Use Your MCP Server

Once the server is running (either deployed in Azure or locally), follow these steps:

  1. Open GitHub Copilot Chat in VS Code
  2. Change the mode to Agent by clicking the dropdown in the chat panel
  3. Click the Select Tools... button, then Add More Tools
Set GitHub Copilot mode to Agent

Selecting the Connection Type

GitHub Copilot supports several ways to connect to MCP servers:

All MCP Server types

There are multiple options available - you could have your server in a container or run it via command line. For our scenario, we'll use HTTP.

Note: At the time of writing this post, I needed to use the HTTP URL of the MCP server rather than HTTPS. You can get this URL from the Aspire dashboard by clicking on the resource and checking the available Endpoints.

After selecting your connection type, Copilot will display the configuration file, which you can modify anytime.

GitHub Copilot Chat Configuration

Interacting with Your Custom Tools

Now comes the fun part! You can interact with your MCP server in two ways:

  1. Natural language queries: Ask questions like "How many short URLs do I have?"
  2. Direct tool references: Use the pound sign to call specific tools: "With #azShortURL list all URLs"

The azShortURL is the name we gave to our MCP server in the configuration.

GitHub Copilot question and response example


Key Learnings and Future Directions

Building this MCP server for AzUrlShortener taught me several valuable lessons:

What Worked Well

  • Integration with .NET Aspire was remarkably straightforward
  • The attribute-based approach to defining tools is clean and intuitive
  • The separation of tool definitions from implementation logic keeps the code maintainable

Challenges and Considerations

  • The csharp-SDK is only a few weeks old and still in preview
  • OAuth authentication isn't defined yet (though it's being actively worked on)
  • Documentation is present but evolving rapidly as the technology matures, so some features may not be fully documented yet

For the AzUrlShortener project specifically, I'm keeping this MCP server implementation in the experimental branch mcp-server until I can properly secure it. However, I'm already envisioning numerous other scenarios where MCP servers could add great value.

If you're interested in exploring this technology, I encourage you to:

  • Check out the GitHub repo
  • Fork it and create your own MCP server
  • Experiment with different tools and capabilities

Join the Community

If you have questions or want to share your experiences with others, I invite you to join the Azure AI Community Discord server:

Join Azure AI Community Discord

The MCP ecosystem is growing rapidly, and it's an exciting time to be part of this community!


~Frank


Reading Notes #644

This post gathers my recent reading notes on artificial intelligence, programming, and a few inspiring podcasts. It includes links to articles, tutorials, and fascinating discussions. Whether you're interested in the latest AI developments, .NET tools, or modern architectures, there's plenty here to spark your curiosity. 


Happy reading!

AI


Programming


Podcasts

Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

~Frank

Reading Notes #643

In this week Reading Notes, we explore a diverse range of updates and insights from the tech world. From the latest features in the Azure SDK and Developer CLI, to an introduction to .NET Aspire and its innovative approach to Infrastructure as Code, there's plenty to catch up on. 

Jump into discussions on AI productivity, free Azure SQL tiers, and even a refreshing podcast on stress-free living. 


Let's get started!


Cloud

Databases

AI

Programming

Podcasts


Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 


If you have interesting content, share it!

~Frank