Skip to content

Instantly share code, notes, and snippets.

View wullemsb's full-sized avatar

Wullems Bart wullemsb

View GitHub Profile
// Define tool functions
static string GetWeather(string city) => $"Weather in {city}: 18°C, partly cloudy."; // Replace with real API call
static string GetForecast(string city, int days) => $"{days}-day forecast for {city}: mostly sunny with occasional showers.";
// Create tool descriptors
var weatherTools = new[]
{
AIFunctionFactory.Create(GetWeather, "get_weather", "Get the current weather for a city"),
AIFunctionFactory.Create(GetForecast, "get_forecast", "Get a multi-day weather forecast"),
};
using Microsoft.Agents.AI.DevUI;
using Microsoft.Agents.AI.Hosting;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.AI;
using OllamaSharp;
using OpenTelemetry.Resources;
using System.Net;
var builder = WebApplication.CreateBuilder(args);
.AddMcpServer(options =>
{
options.ServerInfo = new Implementation
{
Name = "My MCP Server",
Version = "1.0.0",
Title = "My MCP Server",
WebsiteUrl = "http://localhost:5295/",
Icons = [
new Icon
.WithTools([
McpServerTool.Create(
typeof(EchoTool).GetMethod(nameof(EchoTool.Echo))!,
options: new McpServerToolCreateOptions
{
Icons = [
new Icon
{
Source = "http://localhost:5295/echo-icon-light.svg",
MimeType = "image/svg+xml",
[McpServerTool(Title = "Echo", IconSource = "http://localhost:5295/echo-icon.svg")]
public static string Echo(string message) => message;
{
"version": 1,
"hooks": {
"postToolUse": [
{
"type": "command",
"powershell": "./.github/hooks/scripts/format-csharp.ps1",
"timeoutSec": 30
}
]
$input_data = [Console]::In.ReadToEnd() | ConvertFrom-Json
$toolName = $input_data.toolName
$toolArgs = $input_data.toolArgs | ConvertFrom-Json
$filePath = $toolArgs.path
# Only act on edit/create tools touching a .cs file
if ($toolName -notin @("edit", "create")) { exit 0 }
if (-not $filePath.EndsWith(".cs")) { exit 0 }
using OpenTelemetry.Resources;
builder.Services.AddOpenTelemetry()
.ConfigureResource(r => r.AddAttributes(new[]
{
new KeyValuePair<string, object>(
"runtime.dotnet.version",
Environment.Version.ToString()
)
}))
ALTER USER [usr_SampleDB_reader]
WITH NAME = [usr_SampleDB_reader], -- preserve the username
LOGIN = [VLM\lg_SampleDB_dev_db-reader];
USE [ONT_SampleDB];
GO
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'usr_SampleDB_reader')
BEGIN
ALTER USER [usr_SampleDB_reader] WITH LOGIN = [lg_SampleDB_dev_db-reader];
END
ELSE
BEGIN
CREATE USER [usr_SampleDB_reader] FOR LOGIN [lg_SampleDB_dev_db-reader];
END