mcp-server-demo

HemSoft/mcp-server-demo

3.2

If you are the rightful owner of mcp-server-demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A sample Model Context Protocol (MCP) server built with C# and .NET that demonstrates how to create custom tools for AI assistants.

Tools
2
Resources
0
Prompts
0

MCP Server Demo

A sample Model Context Protocol (MCP) server built with C# and .NET that demonstrates how to create custom tools and resources for AI assistants. This server provides two simple tools (Echo and ReverseEcho) and one resource (Text).

Features

  • Echo Tool: Returns a greeting message with the input text
  • ReverseEcho Tool: Returns the input text with characters reversed
  • AnalyzeWithElicitation Tool: Demonstrates server elicitation by calling the client's LLM for analysis
  • Text Resource: Provides a simple text resource for AI assistants
  • Prompt Templates: Reusable prompt templates for text summarization, sentiment analysis, and idea generation
  • Built with ModelContextProtocol.Server v0.4.0-preview.2
  • Compatible with any MCP host (VS Code, Claude Desktop, etc.)

Prerequisites

  • .NET 8.0 or later
  • VS Code with GitHub Copilot extension (for VS Code integration)

Building the Server

  1. Clone this repository:

    git clone https://github.com/HemSoft/mcp-server-demo.git
    cd mcp-server-demo
    
  2. Build the project:

    dotnet build
    
  3. Run the server (for testing):

    dotnet run
    

Using with VS Code

To use this MCP server with VS Code and GitHub Copilot:

Method 1: Using the VS Code MCP Extension

  1. Install the MCP extension in VS Code
  2. Open VS Code settings and navigate to the MCP configuration
  3. Add a new server configuration:
    {
      "mcpServers": {
        "mcp-server-demo": {
          "command": "dotnet",
          "args": ["run", "--project", "path/to/mcp-server-demo/mcp-server-demo.csproj"],
          "env": {}
        }
      }
    }
    

Method 2: Using MCP Configuration File

  1. Create or edit the MCP configuration file in your VS Code workspace (.vscode/mcp.json):

    {
      "mcpServers": {
        "mcp-server-demo": {
          "command": "dotnet",
          "args": ["run", "--project", "./mcp-server-demo.csproj"],
          "cwd": "/path/to/your/mcp-server-demo"
        }
      }
    }
    
  2. Restart VS Code or reload the window

  3. The MCP server will be automatically connected when GitHub Copilot starts

Using with Claude Desktop

To use this server with Claude Desktop:

  1. Build the project in Release mode:

    dotnet build -c Release
    
  2. Edit your Claude Desktop configuration file:

    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Linux: ~/.config/claude/claude_desktop_config.json
  3. Add the server configuration:

    {
      "mcpServers": {
        "mcp-server-demo": {
          "command": "dotnet",
          "args": ["path/to/mcp-server-demo/bin/Release/net8.0/mcp-server-demo.dll"],
          "env": {}
        }
      }
    }
    
  4. Restart Claude Desktop

Available Tools

Echo

  • Description: Echoes the message back to the client with a greeting
  • Parameters:
    • message (string): The message to echo
  • Example: Input "Hello World" returns "Hello from C#: Hello World"

ReverseEcho

  • Description: Returns the input message with characters in reverse order
  • Parameters:
    • message (string): The message to reverse
  • Example: Input "Hello World" returns "dlroW olleH"

AnalyzeWithElicitation

  • Description: Analyzes text by calling back to the client's LLM (demonstrates elicitation/sampling)
  • Parameters:
    • text (string): The text to analyze
  • Example: Input "The project launched successfully" returns key insights extracted by the client's LLM
  • Advanced: This tool demonstrates MCP elicitation - the server calls the client's LLM to get intelligent analysis, then returns the result

Available Resources

Text Resource

  • Description: Provides a simple text resource that returns "Hello from C#"
  • URI: Can be accessed through MCP resource calls
  • Usage: AI assistants can retrieve this resource to get the static text content

Elicitation (Sampling)

Elicitation is when an MCP server calls back to the client's LLM to get intelligent responses during tool execution. This enables servers to leverage the client's language model for dynamic analysis or processing.

The AnalyzeWithElicitation tool demonstrates this pattern by:

  1. Receiving user input (text to analyze)
  2. Calling back to the client's LLM via thisServer.AsSamplingChatClient()
  3. Sending a prompt to the LLM
  4. Returning the LLM's response to the user

This is different from prompts, which are static templates. Elicitation enables dynamic, context-aware server behavior.

Available Prompts

Prompts are reusable templates that guide AI assistants in performing specific tasks. They can be parameterized with user input.

SummarizePrompt

  • Description: A prompt template for summarizing text content
  • Parameters:
    • content (string): The text content to summarize
  • Example: Summarize a long article into 2-3 sentences
  • Usage: Ask the AI to "Use the SummarizePrompt to summarize this article..."

SentimentAnalysisPrompt

  • Description: A prompt template for analyzing sentiment of text
  • Parameters:
    • text (string): The text to analyze
  • Example: Analyze whether a review is positive, negative, or neutral
  • Usage: Ask the AI to "Use the SentimentAnalysisPrompt to analyze this review..."

IdeaGeneratorPrompt

  • Description: A prompt template for generating creative ideas
  • Parameters:
    • topic (string): The topic or theme for ideation
  • Example: Generate 5 innovative ideas related to "sustainable technology"
  • Usage: Ask the AI to "Use the IdeaGeneratorPrompt for ideas about..."

Testing the Server

Once connected to an MCP host, you can test the tools by asking the AI assistant to:

  • "Echo the message 'Hello MCP'"
  • "Reverse the string 'Once upon a time'"
  • "Analyze this text with the AnalyzeWithElicitation tool: [your text here]"

You can test the resource by asking the AI assistant to:

  • "Access the text resource from the MCP server"
  • "Retrieve the available text content"

You can test the prompts by asking the AI assistant to:

  • "Use the SummarizePrompt to summarize this text..."
  • "Use the SentimentAnalysisPrompt to analyze this review..."
  • "Use the IdeaGeneratorPrompt to generate ideas about..."

Troubleshooting

Server Not Connecting

  • Ensure .NET 8.0 is installed and accessible via the dotnet command
  • Check that the file paths in your configuration are correct
  • Verify the server builds without errors (dotnet build)

Tools Not Available

  • Restart your MCP host application
  • Check the MCP host logs for connection errors
  • Ensure the configuration JSON is valid

Development

This project demonstrates the basic structure of an MCP server in C#:

  • Program.cs: Main entry point with tool, resource, and prompt definitions
  • mcp-server-demo.csproj: Project file with dependencies
  • Uses ModelContextProtocol.Server v0.4.0-preview.2

To add new tools:

  1. Create a new static method in the EchoTool class (or create a new class)
  2. Decorate with [McpServerTool] and [Description] attributes
  3. Rebuild and restart the server

To add new resources:

  1. Create a new static method in the EchoResource class (or create a new class)
  2. Decorate with [McpServerResource] and [Description] attributes
  3. Rebuild and restart the server

To add new prompts:

  1. Create a new static method in the DemoPrompts class (or create a new class)
  2. Decorate the class with [McpServerPromptType] and methods with [McpServerPrompt] and [Description] attributes
  3. Return a ChatMessage with ChatRole.User and your prompt template
  4. Rebuild and restart the server

License

This project is licensed under the MIT License - see the LICENSE file for details.