Building a Self-Improving MCP Server Tool for Claude Desktop in C# (Console App)

What if I told you that Claude could help you build a tool… that Claude itself uses… to become even more capable? And then Claude could improve that tool further, creating a beautiful loop of enhancement?

Well, in the year of 2025, something like this it’s not so much like sci-fi anymore, right? But it’s real, it’s simple, and by the end of this article, you’ll have built it yourself.


The Journey We’re Taking Together

Today, we’re building a custom MCP (Model Context Protocol) server. Don’t let the fancy name intimidate you – at its heart, it’s just a simple program that gives Claude new abilities. We’ll start with something beautifully simple: reading and writing files.

“But wait,” you might say, “Claude Desktop already has a Filesystem connector!”

True! But here’s where it gets interesting: we’re going to build our own from scratch, and in doing so, you’ll understand how to give Claude any capability you can imagine. This is just the beginning.


Step 1: Setting Up Your Workspace

First, let’s get Claude Desktop ready for this adventure.

Install Claude Desktop (if you haven’t already)

Then, let’s configure it:

  1. Open Claude Desktop
  2. Go to Settings → Features
  3. Enable “Code execution and file creation”
  4. Go to Settings → Connectors
  5. Enable the “Filesystem” connector
  6. Click “Configure” → Allow all tools
  7. Add an allowed directory: D:\Claude Files

This gives us a playground where Claude can help us build our tool.


Step 2: Creating Our Console App

Create a new folder for your project:

D:\Claude Files\my_mcp\

Open Visual Studio and create a new Console App (.NET Framework). Your project structure will look like this:

D:\Claude Files\my_mcp\MyMcp.sln
D:\Claude Files\my_mcp\MyMcp\Program.cs
D:\Claude Files\my_mcp\MyMcp\MyMcp.csproj

Your Program.cs starts beautifully blank:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMcp
{
    internal class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

Step 3: Here’s Where the Magic Happens

Now, open Claude Desktop and have a conversation. Here’s the crucial part – you need to tell Claude exactly where your project is:

A Different Approach: No SDK Required

You might have heard about MCP SDKs – Python SDK, TypeScript SDK, C# SDK – being used to build MCP servers for Claude Desktop. SDKs provide helpful abstractions and serve as convenient tools… primarily for humans. They handle the complexity, provide nice APIs, and make development smoother.

But here’s an interesting realization: Claude might not need an SDK at all.

The Model Context Protocol is just a specification – a document describing how to communicate via JSON-RPC over stdin/stdout. And Claude can read that specification directly.

So instead of installing an SDK, learning its API, and writing code against it… we’re going to do something simpler:

We’re going to ask Claude to read the MCP specification and write code that implements it directly.

No SDK installation. No dependency management. Just Claude, the specification document, and whatever programming language you prefer.

This is the beauty of AI-assisted development: when your coding partner can read and understand protocol specifications, it can generate compliant implementations on demand, in any language.

Claude, help me write a C# console app to build a custom MCP for Claude Desktop.
Please read the latest documentation on the requirements, protocol, and procedures
for building an MCP specifically for Claude Desktop.
Make sure it follows the latest specification for integrating
with Claude Desktop MCP Connectors.

The project is located at:

D:\Claude Files\my_mcp
D:\Claude Files\my_mcp\MyMcp.sln
D:\Claude Files\my_mcp\MyMcp\Program.cs
D:\Claude Files\my_mcp\MyMcp\MyMcp.csproj

I need two simple tools:

- to read a file's content
- to write content to a file

Why the explicit paths? Claude needs to know where to find your files. You could ask Claude to search D:\Claude Files, but being explicit saves time and avoids confusion. Think of it as giving clear directions to a helpful friend.

Then… watch Claude work its magic.

Claude will:

  1. Read the existing Program.cs
  2. Research the MCP protocol specifications
  3. Transform that empty Program.cs into a fully functional MCP server

The generated code will handle:

  • JSON-RPC protocol communication
  • Tool registration and discovery
  • Request parsing and response formatting
  • Error handling
  • File operations with proper encoding

Before: An empty Main method
After: A complete MCP server with read_file and write_file tools

(I’m not showing the full generated code here because Claude will write it fresh for you, potentially with improvements based on the latest MCP specs. That’s part of the beauty!)


Step 4: Build and Deploy

In Visual Studio, build your project (F6 or Build → Build Solution).

Your shiny new executable will be here:

D:\Claude Files\my_mcp\MyMcp\bin\Debug\MyMcp.exe

Step 5: Installing Your MCP

Now for the connection ritual:

Close Claude Desktop completely:

  • Close the window
  • Open Task Manager (Ctrl+Shift+Esc)
  • Find and end the Claude Desktop process (and any child processes)

Edit the configuration file:

Navigate to:

%APPDATA%\Claude\claude_desktop_config.json

Before:

{}

After:

{
  "mcpServers": {
    "MyMcp": {
      "command": "D:\\Claude Files\\my_mcp\\MyMcp\\bin\\Debug\\MyMcp.exe",
      "args": []
    }
  }
}

(Notice the double backslashes – that’s important in JSON!)


Step 6: The Moment of Truth

Restart Claude Desktop

Go to Settings → Connectors:

  • Disable the default “Filesystem” connector (for testing purposes)
  • Enable your new “MyMcp” connector
  • Configure “MyMcp” → Allow all tools

Showtime! Let’s Test It

Test 1: Writing a File

Claude, help me create a text file at the following path:

D:\Claude Files\helloworld.txt

Content: Hello World!

Claude will use your custom tool to create the file. Check your folder – there it is!

Test 2: Reading It Back

Claude, read the file and tell me what you see:

D:\Claude Files\helloworld.txt

Claude responds: “Hello World!”

Step 7: The Secret Sauce – Documentation

Here’s something that separates a good MCP from a great one: documentation.

Remember, Claude will be using your tools. But how does Claude know what your tools can do? How does it know the best practices? The common patterns? The clever use cases?

That’s where your documentation comes in.

Create a file called TOOL_DEFINITION.md in your project folder:

D:\Claude Files\my_mcp\TOOL_DEFINITION.md

But Who Writes the Documentation?

Here’s the beautiful part: Claude writes its own documentation.

Think about it – who better to write documentation for Claude than Claude itself? Claude knows exactly what information future instances of Claude need.

Open Claude Desktop and prompt something like this:

Claude, we're going to write documentation to teach future instances
of Claude how to use this MCP. Imagine you're a new Claude
discovering this tool for the first time - how would you teach
yourself in the most optimal way? How would you structure the
information so you can efficiently learn the tool, understand
its behavior, and have correct expectations for outcomes?

Write the documentation to this file:

D:\Claude Files\my_mcp\TOOL_DEFINITION.md

Claude will then generate documentation like this:

# MyMcp Tool Definition

## Available Tools

### read_file
**Description:** Read the complete content of a text file.

**Parameters:**
- `path` (string, required): Full path to the file to read

**Returns:** File content as string

**Example Usage:**
"Claude, read the file at D:\Claude Files\config.txt"

**Best Practices:**
- Always use absolute paths
- File must exist or tool returns error
- Works with text files (.txt, .md, .cs, .json, etc.)

---

### write_file
**Description:** Write content to a file. Creates new file or overwrites existing.

**Parameters:**
- `path` (string, required): Full path to the file
- `content` (string, required): Content to write

**Returns:** Success confirmation

**Example Usage:**
"Claude, write 'Hello World' to D:\Claude Files\test.txt"

**Best Practices:**
- File will be overwritten if it exists
- Parent directory must exist
- Use UTF-8 encoding for special characters

Why is this important?

When you ask Claude to use your MCP, Claude can read this documentation first. This helps Claude:

  1. Understand capabilities – Know exactly what each tool does
  2. Use correct parameters – Get the parameter names and types right
  3. Follow best practices – Learn the optimal way to use each tool
  4. Discover use cases – See examples and workflows
  5. Avoid mistakes – Understand limitations and edge cases

Think of it as Claude leaving a manual for itself. Claude writes documentation in the way Claude best understands.

Claude writes the code. Claude writes the documentation. Claude improves both.

The documentation evolves with your code, written by the same intelligence that will read it later. It’s the perfect feedback loop.


The Beautiful Realizations

Take a moment. Let that sink in. What just happened here?

Insight #1: Beyond SDKs and Language Barriers

MCP servers don’t have to be built with official SDKs. While Python, TypeScript, and C# SDKs exist and are genuinely helpful for traditional development, there’s another path:

When Claude reads the MCP specification directly, any language becomes viable.

The MCP protocol is just JSON-RPC over stdin/stdout. That’s it. Any program that can:

  • Read from standard input
  • Write to standard output
  • Parse and generate JSON

…can be an MCP server.

This opens the door to:

  • C#
  • C and C++
  • Java
  • Go
  • Rust
  • VB.NET
  • Even Bash scripts or PowerShell

The SDK is optional when AI can read the spec. This is the paradigm shift: instead of learning SDK APIs, you describe what you want to Claude, and Claude generates spec-compliant code in whatever language you choose.

The world just got a lot bigger.

Insight #2: You Built a Bridge

That simple console app? It’s a tunnel. A gateway. A bridge connecting Claude’s intelligence with your computer’s hardware and software ecosystem.

Claude can now touch your machine in ways it couldn’t before.

Insight #3: The Possibilities Just Exploded

Think about what this means. If you can write C# code to do something, Claude can now do it:

Hardware & IoT:

  • Turn on your smart lights
  • Start your coffee maker
  • Control your 3D printer
  • Operate any device with an API

Web & APIs:

  • Access any REST API via HttpClient
  • Scrape websites
  • Post to social media
  • Trigger webhooks

Data & Databases:

  • Query SQL Server, MySQL, PostgreSQL
  • Access MongoDB, Redis
  • Read from CSV, JSON, XML
  • Generate reports

System Operations:

  • Run Git commands
  • Execute bash scripts
  • Compile and run code
  • Manage processes

Document Processing:

  • Read complex Excel files (EPPlus, ClosedXML)
  • Parse Word documents (DocX)
  • Extract PDF content (iTextSharp)
  • Generate barcodes and QR codes

Advanced Operations:

  • Process payments via Stripe API
  • Send emails via SMTP
  • Generate images via graphics libraries
  • Perform complex calculations

The limit is your imagination.

Insight #4: The Self-Improving Tool

Here’s where it gets really wild.

Claude has full access to your MCP’s source code (it’s in the allowed directory, remember?). So you can say:

Claude, add a new tool to MyMcp that can list all files in a directory.

And Claude will:

  1. Read Program.cs
  2. Understand the existing structure
  3. Add the new tool following the same patterns
  4. Write the updated code

You rebuild, restart, and boom – Claude just improved its own capabilities.

This is a tool that grows with your needs, guided by conversation.


What This Really Means

You’ve just crossed a threshold. You’re not just using Claude anymore – you’re extending it.

Every problem you solve, every tool you add, makes Claude more capable in your specific context. It’s like having a programming assistant that helps you build better tools for itself.

And here’s the beautiful part: you don’t need to be an expert. Claude helps you write the code. Claude helps you debug. Claude helps you improve. You’re in a partnership where the AI helps you build the very tools that make the AI more useful to you.


Where Do You Go From Here?

This simple read/write MCP is just the seed. Here are some natural next steps:

First Things First:

  • Write comprehensive documentation – The better your TOOL_DEFINITION.md, the smarter Claude becomes
  • Create usage examples for each tool
  • Document common workflows and patterns
  • Include troubleshooting tips

Easy Enhancements:

  • Add file deletion
  • Add directory listing
  • Add file copying/moving
  • Add file search

Medium Challenges:

  • Add database connectivity
  • Add HTTP request capabilities
  • Add Excel/Word reading
  • Add JSON/XML parsing

Advanced Adventures:

  • Add code compilation and execution
  • Add image processing
  • Add API integrations for your favorite services
  • Add hardware control via serial port

The Meta Level:
Build an MCP that can modify and rebuild itself, then restart Claude Desktop automatically. Yes, seriously.


A Parting Thought

We started with an empty Program.cs and a simple dream: let Claude read and write files.

But what we actually built was something more profound – a bridge between human intention and machine capability, where the machine helps improve the bridge itself.

This is the future of human-AI collaboration: not just using tools, but building tools together, in conversation, where the line between user and developer blurs into something new.

So go ahead, friend. Build your MCP. See what Claude can help you create. And then watch as your creation grows, tool by tool, conversation by conversation, into something uniquely yours.

The door is open. What will you build?

Feature Image by Alexandra_Koch from Pixabay