MCP Text Transform Server

by msv2017

285 downloads
Not rated
GitHub

Description

# MCP Text Transform Server A **Model Context Protocol (MCP) server** implementation in C# .NET 9 that provides text transformation tools. This server is compatible with Claude Desktop and other MCP clients. > 📖 **Learn more about MCP**: Visit the [official Model Context…

About

# MCP Text Transform Server A **Model Context Protocol (MCP) server** implementation in C# .NET 9 that provides text transformation tools. This server is compatible with Claude Desktop and other MCP clients. > 📖 **Learn more about MCP**: Visit the [official Model Context Protocol…

Details

Author
msv2017
Downloads
285
Categories
Developer Tools

- CapitalCase tool (capital_case) converts text to Title Case, intelligently handling camelCase.
- SnakeCase tool (snake_case) converts to snake_case from camelCase, PascalCase, or spaces.
- Uses the official ModelContextProtocol SDK with STDIO transport.
- Attribute‑based tool registration via [McpServerTool].
- Built on .NET 9 with dependency injection and structured logging.
- Compatible with any MCP client that supports the STDIO transport.

Build the project with dotnet build and run with dotnet run. To integrate with Claude Desktop, add a text-transform entry to its configuration pointing to the project with dotnet run --project /path/to/McpServer.csproj --no-build. Tools can then be invoked via natural language prompts or JSON‑RPC calls.

# MCP Text Transform Server A **Model Context Protocol (MCP) server** implementation in C# .NET 9 that provides text transformation tools. This server is compatible with Claude Desktop and other MCP clients. > 📖 **Learn more about MCP**: Visit the [official Model Context Protocol documentation](https://modelcontextprotocol.io/quickstart/server) for comprehensive guides and examples. ## ✨ Features This MCP server provides two powerful text transformation tools: 1. **CapitalCase Tool** (`capital_case`) - Converts text to Capital Case (Title Case) format - Handles camelCase/PascalCase by intelligently adding spaces - Example: `"camelCaseExample"` → `"Camel Case Example"` 2. **SnakeCase Tool** (`snake_case`) - Converts text to snake_case format - Handles camelCase, PascalCase, and spaces - Example: `"HelloWorld"` → `"hello_world"` ## 🏗️ Architecture This project uses the **official Model Context Protocol SDK** and follows modern C# practices: - **MCP Protocol Compliance**: Uses `ModelContextProtocol` NuGet package - **STDIO Transport**: Communicates via standard input/output (JSON-RPC) - **Attribute-Based Tools**: Simple `[McpServerTool]` decoration - **Dependency Injection**: Built-in .NET DI container - **Structured Logging**: Configured for MCP compatibility (stderr) - **Modern C# Features**: .NET 9, nullable reference types, async patterns ## 📁 Project Structure ``` McpServer/ ├── Tools/ # MCP tool implementations │ └── TextTransformTools.cs # Capital case & snake case tools ├── Program.cs # MCP server entry point ├── McpServer.csproj # Project file with MCP SDK └── README.md # This documentation ``` ## 🚀 Getting Started ### Prerequisites - .NET 9.0 SDK or later - Claude Desktop (for testing MCP integration) ### Building the Server ```bash # Clone and build git clone <repository-url> cd test-mcp-server dotnet build # Test the server dotnet run ``` ### Testing the Tools The server provides these text transformation capabilities: ``` Input: "camelCaseExample" ├── CapitalCase → "Camel Case Example" └── SnakeCase → "camel_case_example" Input: "Hello World" ├── CapitalCase → "Hello World" └── SnakeCase → "hello_world" ``` ## 🖥️ Claude Desktop Integration To use this MCP server with Claude Desktop, add the following configuration: ### Step 1: Locate Claude Desktop Config **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` **Linux**: `~/.config/Claude/claude_desktop_config.json` ### Step 2: Add Server Configuration ```json { "mcpServers": { "text-transform": { "command": "dotnet", "args": [ "run", "--project", "/path/to/your/test-mcp-server/McpServer.csproj", "--no-build" ] } } } ``` **Replace `/path/to/your/test-mcp-server` with your actual project path:** **Windows example:** ```json { "mcpServers": { "text-transform": { "command": "dotnet", "args": [ "run", "--project", "C:\\Users\\YourName\\projects\\test-mcp-server\\McpServer.csproj", "--no-build" ] } } } ``` **macOS/Linux example:** ```json { "mcpServers": { "text-transform": { "command": "dotnet", "args": [ "run", "--project", "/home/username/projects/test-mcp-server/McpServer.csproj", "--no-build" ] } } } ``` **Important notes:** - Use **absolute paths** to the `McpServer.csproj` file - Use **double backslashes** (`\\`) on Windows for JSON escaping - Ensure the project file path exists - The `--no-build` flag speeds up server startup (recommended) ### Step 3: Restart Claude Desktop After saving the configuration, restart Claude Desktop. The text transformation tools will be available in your conversations. ### Step 4: Test in Claude Desktop Try these prompts to test the integration: ``` "Please convert 'HelloWorldExample' to capital case" "Transform 'My Example Text' to snake_case format" "Convert 'camelCaseVariable' to title case" ``` ## 🔧 Development ### Adding New Tools To add new MCP tools, simply add methods to the `TextTransformTools` class: ```csharp [McpServerTool] [Description("Your tool description")] public static string YourTool([Description("Input parameter")] string input) { // Your transformation logic return transformedText; } ``` ### Testing Locally ```bash # Build and run dotnet run # Test with JSON-RPC (the server expects MCP protocol messages) echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | dotnet run ``` ## 🛠️ Troubleshooting ### Claude Desktop Not Detecting MCP Server If Claude Desktop doesn't show the text transformation tools, follow these steps: #### 1. Verify Server Works Locally ```bash # Test the server responds to MCP commands: echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | dotnet run ``` #### 2. Check Claude Desktop Configuration **Location of config file:** - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` - **Linux**: `~/.config/Claude/claude_desktop_config.json` **Exact configuration format:** ```json { "mcpServers": { "text-transform": { "command": "dotnet", "args": [ "run", "--project", "/path/to/your/test-mcp-server/McpServer.csproj", "--no-build" ] } } } ``` **Replace `/path/to/your/test-mcp-server` with your actual project path:** **Windows:** ```json "args": [ "run", "--project", "C:\\Users\\YourName\\projects\\test-mcp-server\\McpServer.csproj", "--no-build" ] ``` **macOS/Linux:** ```json "args": [ "run", "--project", "/home/username/projects/test-mcp-server/McpServer.csproj", "--no-build" ] ``` **Important notes:** - Use **absolute paths** to the `McpServer.csproj` file - Use **double backslashes** (`\\`) on Windows for JSON escaping - Ensure the project file path exists and is correct - The `command` should be `dotnet` (not full path) #### 3. Common Issues 1. **"Server not found" in Claude Desktop** - Verify the file path in `claude_desktop_config.json` exists - Ensure the project builds successfully (`dotnet build`) - Check that .NET 9 SDK is installed (`dotnet --version`) - Try using forward slashes `/` instead of backslashes in paths 2. **Server starts but tools not available** - Restart Claude Desktop completely after configuration changes - Check Claude Desktop's console/logs for error messages - Verify the server name in config matches exactly (`text-transform`) 3. **Build errors** - Run `dotnet restore` to ensure all NuGet packages are installed - Verify you have .NET 9.0 SDK or later - Try `dotnet clean` followed by `dotnet build` #### 4. Advanced Debugging **Test with manual JSON-RPC:** ```bash # Initialize the server echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0.0"}}}' | dotnet run # List available tools echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}' | dotnet run # Test tool execution echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "CapitalCase", "arguments": {"text": "hello world"}}}' | dotnet run ``` **Check Claude Desktop logs:** - Windows: Look in Event Viewer or Claude's application data folder - macOS: Use Console.app to view logs - Linux: Check system logs or run Claude from terminal ### MCP Protocol Details 2. **Server starts but tools not available** - Restart Claude Desktop after configuration changes - Check the server logs in Claude Desktop's console 3. **Build errors** - Run `dotnet restore` to ensure all NuGet packages are installed - Verify you have .NET 9.0 SDK or later ### MCP Protocol Details This server implements the Model Context Protocol specification: - **Transport**: STDIO (JSON-RPC over stdin/stdout) - **Protocol Version**: Compatible with MCP clients - **Tool Discovery**: Automatic via `[McpServerTool]` attributes - **Error Handling**: Standard JSON-RPC error responses For more details about the MCP protocol, see the [official documentation](https://modelcontextprotocol.io/). ## 📚 Technical Details ### MCP SDK Features Used - `ModelContextProtocol` v0.2.0-preview.2 - STDIO transport for Claude Desktop compatibility - Attribute-based tool registration - Automatic parameter validation and documentation ### Dependencies ```xml <PackageReference Include="ModelContextProtocol" Version="0.2.0-preview.2" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" /> ``` ## 📄 License This project is licensed under the MIT License - see the LICENSE file for details. ## 🤝 Contributing 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Add your new MCP tools or enhancements 4. Commit your changes (`git commit -m 'Add amazing feature'`) 5. Push to the branch (`git push origin feature/amazing-feature`) 6. Open a Pull Request ## 🔮 Roadmap - [ ] Add more text transformation tools (kebab-case, UPPER_CASE, etc.) - [ ] Implement text validation and sanitization tools - [ ] Add support for batch text processing - [ ] Create comprehensive test suite - [ ] Add performance benchmarks "ServerName": "Text Transform MCP Server", "Version": "1.0.0", "Port": 8080, "Logging": { "LogLevel": "Information", "EnableStructuredLogging": true } } } ``` ## Health Check A health check endpoint is available at `/health` to verify the server status. ## Development ### Code Style The project uses `.editorconfig` for consistent code formatting and follows: - PascalCase for classes, methods, properties - camelCase for private fields and parameters - Underscore prefix for private fields (`_fieldName`) - File-scoped namespaces - Nullable reference types enabled ### Logging Structured logging is implemented using `ILogger<T>` with appropriate log levels: - **Debug**: Detailed transformation steps - **Information**: Tool execution and server lifecycle - **Warning**: Invalid inputs or missing tools - **Error**: Exceptions and failures ### Testing The project structure supports unit testing with: - Dependency injection for testability - Interface-based programming - Separation of concerns ## MCP Protocol This server implements the Model Context Protocol for integration with MCP-compatible clients. The tools can be discovered and executed through the standard MCP tool calling interface. ## License This project is provided as-is for educational and development purposes.
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.