Dis service dey provide basic calculator operations wit di Model Context Protocol (MCP). E dey designed as simple example for people wey dey learn MCP implementations.
For more info, check C# SDK
Dis calculator service get di following things wey e fit do:
- Basic Arithmetic Operations:
- Add two numbers together
- Subtract one number from another
- Multiply two numbers
- Divide one number by another (e dey check if di second number na zero)
- Set MCP Servers:
-
Open your workspace for VS Code.
-
Create
.vscode/mcp.jsonfile for your workspace folder to set MCP servers. Example configuration: -
You go need enter di GitHub repository root, wey you fit get from dis command,
git rev-parse --show-toplevel.
-
Di service dey provide di following API endpoints wit MCP protocol:
add(a, b): Add two numbers togethersubtract(a, b): Subtract di second number from di firstmultiply(a, b): Multiply two numbersdivide(a, b): Divide di first number by di second (e dey check if di second number na zero)- isPrime(n): Check if one number na prime
- Try make request to di service wit MCP protocol. Example, you fit ask:
- "Add 5 and 3"
- "Subtract 10 from 4"
- "Multiply 6 and 7"
- "Divide 8 by 2"
- "Does 37854 prime?"
- "What are the 3 prime numbers before after 4242?"
- To make sure say e dey use di tools, add #MyCalculator for di prompt. Example:
- "Add 5 and 3 #MyCalculator"
- "Subtract 10 from 4 #MyCalculator
Di previous solution dey good if you get di .NET SDK installed and all di dependencies dey ready. But if you wan share di solution or run am for different environment, you fit use di containerized version.
- Start Docker and make sure say e dey run.
- From terminal, go to di folder
03-GettingStarted\samples\csharp\src - To build di Docker image for di calculator service, run dis command (replace
<YOUR-DOCKER-USERNAME>wit your Docker Hub username):docker build -t <YOUR-DOCKER-USERNAME>/mcp-calculator .
- After di image don build, make we upload am go Docker Hub. Run dis command:
docker push <YOUR-DOCKER-USERNAME>/mcp-calculator
## Use the Dockerized Version
1. In the `.vscode/mcp.json` file, replace the server configuration by the following:
```json
"mcp-calc": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"<YOUR-DOCKER-USERNAME>/mcp-calc"
],
"envFile": "",
"env": {}
}
If you look di configuration, you go see say di command na docker and di args na run --rm -i <YOUR-DOCKER-USERNAME>/mcp-calc. Di --rm flag dey make sure say di container go remove after e stop, and di -i flag dey allow you interact wit di container standard input. Di last argument na di name of di image wey we just build and push go Docker Hub.
Start di MCP Server by clicking di small Start button wey dey above "mcp-calc": {, and just like before, you fit ask di calculator service to do some math for you.
Disclaimer:
Dis dokyument don use AI translation service Co-op Translator do di translation. Even as we dey try make am accurate, abeg sabi say machine translation fit get mistake or no dey correct well. Di original dokyument for im native language na di main source wey you go fit trust. For important information, e good make professional human translation dey use. We no go fit take blame for any misunderstanding or wrong interpretation wey fit happen because you use dis translation.
{ "inputs": [ { "type": "promptString", "id": "repository-root", "description": "The absolute path to the repository root" } ], "servers": { "calculator-mcp-dotnet": { "type": "stdio", "command": "dotnet", "args": [ "run", "--project", "${input:repository-root}/03-GettingStarted/samples/csharp/src/calculator.csproj" ] } } }