Skip to content

Commit cb42f9e

Browse files
committed
trying to add more context
1 parent 70eae2e commit cb42f9e

File tree

11 files changed

+498
-24
lines changed

11 files changed

+498
-24
lines changed

03-GettingStarted/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ az containerapp create \
372372
373373
- [Java Calculator](./samples/java/calculator/README.md)
374374
- [.Net Calculator](./samples/csharp/)
375-
- [JavaScript Calculator](./samples/javascript/)
376-
- [TypeScript Calculator](./samples/typescript/)
375+
- [JavaScript Calculator](./samples/javascript/README.md)
376+
- [TypeScript Calculator](./samples/typescript/README.md)
377377
- [Python Calculator](./samples/python/)
378378
379379
## Exercise

03-GettingStarted/samples/javascript/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,63 @@
22

33
This is a JavaScript sample for an MCP Server
44

5+
Here's what the calculator portion of it looks like:
6+
7+
```javascript
8+
// Define calculator tools for each operation
9+
server.tool(
10+
"add",
11+
{
12+
a: z.number(),
13+
b: z.number()
14+
},
15+
async ({ a, b }) => ({
16+
content: [{ type: "text", text: String(a + b) }]
17+
})
18+
);
19+
20+
server.tool(
21+
"subtract",
22+
{
23+
a: z.number(),
24+
b: z.number()
25+
},
26+
async ({ a, b }) => ({
27+
content: [{ type: "text", text: String(a - b) }]
28+
})
29+
);
30+
31+
server.tool(
32+
"multiply",
33+
{
34+
a: z.number(),
35+
b: z.number()
36+
},
37+
async ({ a, b }) => ({
38+
content: [{ type: "text", text: String(a * b) }]
39+
})
40+
);
41+
42+
server.tool(
43+
"divide",
44+
{
45+
a: z.number(),
46+
b: z.number()
47+
},
48+
async ({ a, b }) => {
49+
if (b === 0) {
50+
return {
51+
content: [{ type: "text", text: "Error: Cannot divide by zero" }],
52+
isError: true
53+
};
54+
}
55+
return {
56+
content: [{ type: "text", text: String(a / b) }]
57+
};
58+
}
59+
);
60+
```
61+
562
## Install
663

764
Run the following command:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Sample
2+
3+
This is a Python sample for an MCP Server
4+
5+
Here's what the calculator portion looks like:
6+
7+
```python
8+
@mcp.tool()
9+
def add(a: float, b: float) -> float:
10+
"""Add two numbers together and return the result."""
11+
return a + b
12+
13+
@mcp.tool()
14+
def subtract(a: float, b: float) -> float:
15+
"""Subtract b from a and return the result."""
16+
return a - b
17+
18+
@mcp.tool()
19+
def multiply(a: float, b: float) -> float:
20+
"""Multiply two numbers together and return the result."""
21+
return a * b
22+
23+
@mcp.tool()
24+
def divide(a: float, b: float) -> float:
25+
"""
26+
Divide a by b and return the result.
27+
28+
Raises:
29+
ValueError: If b is zero
30+
"""
31+
if b == 0:
32+
raise ValueError("Cannot divide by zero")
33+
return a / b
34+
```
35+
36+
## Install
37+
38+
Run the following command:
39+
40+
```bash
41+
pip install mcp
42+
```
43+
44+
## Run
45+
46+
```bash
47+
python mcp_calculator_server.py
48+
```

03-GettingStarted/samples/typescript/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,63 @@
22

33
This is a Typescript sample for an MCP Server
44

5+
Here's what the calculator portion looks like:
6+
7+
```typescript
8+
// Define calculator tools for each operation
9+
server.tool(
10+
"add",
11+
{
12+
a: z.number(),
13+
b: z.number()
14+
},
15+
async ({ a, b }) => ({
16+
content: [{ type: "text", text: String(a + b) }]
17+
})
18+
);
19+
20+
server.tool(
21+
"subtract",
22+
{
23+
a: z.number(),
24+
b: z.number()
25+
},
26+
async ({ a, b }) => ({
27+
content: [{ type: "text", text: String(a - b) }]
28+
})
29+
);
30+
31+
server.tool(
32+
"multiply",
33+
{
34+
a: z.number(),
35+
b: z.number()
36+
},
37+
async ({ a, b }) => ({
38+
content: [{ type: "text", text: String(a * b) }]
39+
})
40+
);
41+
42+
server.tool(
43+
"divide",
44+
{
45+
a: z.number(),
46+
b: z.number()
47+
},
48+
async ({ a, b }) => {
49+
if (b === 0) {
50+
return {
51+
content: [{ type: "text", text: "Error: Cannot divide by zero" }],
52+
isError: true
53+
};
54+
}
55+
return {
56+
content: [{ type: "text", text: String(a / b) }]
57+
};
58+
}
59+
);
60+
```
61+
562
## Install
663

764
Run the following command:

04-PracticalImplementation/README.md

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Practical Implementation
22

3+
Practical implementation is where the power of the Model Context Protocol (MCP) becomes tangible. While understanding the theory and architecture behind MCP is important, the real value emerges when you apply these concepts to build, test, and deploy solutions that solve real-world problems. This chapter bridges the gap between conceptual knowledge and hands-on development, guiding you through the process of bringing MCP-based applications to life.
4+
5+
Whether you are developing intelligent assistants, integrating AI into business workflows, or building custom tools for data processing, MCP provides a flexible foundation. Its language-agnostic design and official SDKs for popular programming languages make it accessible to a wide range of developers. By leveraging these SDKs, you can quickly prototype, iterate, and scale your solutions across different platforms and environments.
6+
7+
In the following sections, you'll find practical examples, sample code, and deployment strategies that demonstrate how to implement MCP in C#, Java, TypeScript, JavaScript, and Python. You'll also learn how to debug and test your MCP servers, manage APIs, and deploy solutions to the cloud using Azure. These hands-on resources are designed to accelerate your learning and help you confidently build robust, production-ready MCP applications.
8+
39
## Overview
410

511
This lesson focuses on practical aspects of MCP implementation across multiple programming languages. We'll explore how to use MCP SDKs in C#, Java, TypeScript, JavaScript, and Python to build robust applications, debug and test MCP servers, and create reusable resources, prompts, and tools.
@@ -39,31 +45,31 @@ The repository includes sample implementations in the following languages:
3945

4046
Each sample demonstrates key MCP concepts and implementation patterns for that specific language and ecosystem.
4147

42-
### Core Server Features
48+
## Core Server Features
4349

4450
MCP servers can implement any combination of these features:
4551

46-
#### Resources
52+
### Resources
4753
Resources provide context and data for the user or AI model to use:
4854
- Document repositories
4955
- Knowledge bases
5056
- Structured data sources
5157
- File systems
5258

53-
#### Prompts
59+
### Prompts
5460
Prompts are templated messages and workflows for users:
5561
- Pre-defined conversation templates
5662
- Guided interaction patterns
5763
- Specialized dialogue structures
5864

59-
#### Tools
65+
### Tools
6066
Tools are functions for the AI model to execute:
6167
- Data processing utilities
6268
- External API integrations
6369
- Computational capabilities
6470
- Search functionality
6571

66-
#### Sample Implementations
72+
## Sample Implementations: C#
6773

6874
The official C# SDK repository contains several sample implementations demonstrating different aspects of MCP:
6975

@@ -73,7 +79,6 @@ The official C# SDK repository contains several sample implementations demonstra
7379
- **ASP.NET Integration**: Examples demonstrating integration with ASP.NET Core
7480
- **Tool Implementation Patterns**: Various patterns for implementing tools with different complexity levels
7581

76-
### C# .NET Implementation
7782
The MCP C# SDK is in preview and APIs may change. We will continuously update this blog as the SDK evolves.
7883

7984
### Key Features
@@ -82,11 +87,12 @@ The MCP C# SDK is in preview and APIs may change. We will continuously update th
8287
- Building your [first MCP Server](https://devblogs.microsoft.com/dotnet/build-a-model-context-protocol-mcp-server-in-csharp/).
8388

8489
For complete C# implementation samples, visit the [official C# SDK samples repository](https://github.com/modelcontextprotocol/csharp-sdk)
85-
### Java Implementation
90+
91+
## Sample implementation: Java Implementation
8692

8793
The Java SDK offers robust MCP implementation options with enterprise-grade features.
8894

89-
#### Key Features
95+
### Key Features
9096

9197
- Spring Framework integration
9298
- Strong type safety
@@ -95,11 +101,11 @@ The Java SDK offers robust MCP implementation options with enterprise-grade feat
95101

96102
For a complete Java implementation sample, see [MCPSample.java](samples/java/MCPSample.java) in the samples directory.
97103

98-
### JavaScript Implementation
104+
## Sample implementation: JavaScript Implementation
99105

100106
The JavaScript SDK provides a lightweight and flexible approach to MCP implementation.
101107

102-
#### Key Features
108+
### Key Features
103109

104110
- Node.js and browser support
105111
- Promise-based API
@@ -108,11 +114,11 @@ The JavaScript SDK provides a lightweight and flexible approach to MCP implement
108114

109115
For a complete JavaScript implementation sample, see [mcp_sample.js](samples/javascript/mcp_sample.js) in the samples directory.
110116

111-
### Python Implementation
117+
## Sample implementation: Python Implementation
112118

113119
The Python SDK offers a Pythonic approach to MCP implementation with excellent ML framework integrations.
114120

115-
#### Key Features
121+
### Key Features
116122

117123
- Async/await support with asyncio
118124
- Flask and FastAPI integration
@@ -121,19 +127,51 @@ The Python SDK offers a Pythonic approach to MCP implementation with excellent M
121127

122128
For a complete Python implementation sample, see [mcp_sample.py](samples/python/mcp_sample.py) in the samples directory.
123129

124-
### API Management
130+
## API management
131+
132+
Azure API Management is a great answer to how we can secure MCP Servers. The idea is to put an Azure API Management instance in front of your MCP Server and let it handle features you're likely to want like:
133+
134+
- rate limiting
135+
- token management
136+
- monitoring
137+
- load balancing
138+
- security
139+
140+
### Azure Sample
141+
142+
Here's an Azure Sample doing exactly that, i.e [creating an MCP Server and securing it with Azure API Management])(https://github.com/Azure-Samples/remote-mcp-apim-functions-python).
143+
144+
See how the authorization flow happens in below image:
145+
146+
![APIM-MCP](https://github.com/Azure-Samples/remote-mcp-apim-functions-python/blob/main/mcp-client-authorization.gif?raw=true)
147+
148+
In the preceding image, the following takes place:
149+
150+
- Authentication/Authorization takes place using Microsoft Entra.
151+
- Azure API Management acts as a gateway asnd uses policies to direct and manage traffic.
152+
- Azure Monitor logs all request for further analysis.
125153

126-
Azure API Management acts as the [AI Gateway for MCP servers](https://github.com/Azure-Samples/remote-mcp-apim-functions-python).
154+
#### Authorization flow
127155

128-
![APIM-MCP](https://github.com/Azure-Samples/remote-mcp-apim-functions-python/blob/main/mcp-client-authorization.gif)
156+
Let's have a look at the authorization flow more in detail:
129157

130-
This sample implements the latest [MCP Authorization specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization#2-10-third-party-authorization-flow)
131-
This is a Sequence Diagram
158+
![Sequence Diagram](https://github.com/Azure-Samples/remote-mcp-apim-functions-python/blob/main/infra/app/apim-oauth/diagrams/images/mcp-client-auth.png?raw=true)
132159

133-
![Sequence Diagram](https://github.com/Azure-Samples/remote-mcp-apim-functions-python/blob/main/infra/app/apim-oauth/diagrams/images/mcp-client-auth.png)
160+
#### MCP authorization specification
161+
162+
Learn more about the [MCP Authorization specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization#2-10-third-party-authorization-flow)
134163

135164
## Deploy Remote MCP Server to Azure
136165

166+
Let's see if we can deploy the sample we mentioned earlier:
167+
168+
1. Clone the repo
169+
170+
```bash
171+
git clone https://github.com/Azure-Samples/remote-mcp-apim-functions-python.git
172+
cd remote-mcp-apim-functions-python
173+
```
174+
137175
1. Register `Microsoft.App` resource provider.
138176
* If you are using Azure CLI, run `az provider register --namespace Microsoft.App --wait`.
139177
* If you are using Azure PowerShell, run `Register-AzResourceProvider -ProviderNamespace Microsoft.App`. Then run `(Get-AzResourceProvider -ProviderNamespace Microsoft.App).RegistrationState` after some time to check if the registration is complete.
@@ -144,14 +182,20 @@ This is a Sequence Diagram
144182
azd up
145183
```
146184

147-
### MCP Inspector
185+
This commands should deploy all the cloud resources on Azure
186+
187+
### Testing your server with MCP Inspector
148188

149189
1. In a **new terminal window**, install and run MCP Inspector
150190

151191
```shell
152192
npx @modelcontextprotocol/inspector
153193
```
154194

195+
You should see an interface similar to:
196+
197+
![Connect to Node inspector](./assets/connect.png)
198+
155199
1. CTRL click to load the MCP Inspector web app from the URL displayed by the app (e.g. http://127.0.0.1:6274/#resources)
156200
1. Set the transport type to `SSE`
157201
1. Set the URL to your running API Management SSE endpoint displayed after `azd up` and **Connect**:
@@ -162,7 +206,9 @@ This is a Sequence Diagram
162206

163207
5. **List Tools**. Click on a tool and **Run Tool**.
164208

165-
### Implementations and Deployment
209+
If all the steps have worked, you should now be connected to the MCP server and you've been able to call a tool.
210+
211+
## MCP servers for Azure
166212
167213
[Remote-mcp-functions](https://github.com/Azure-Samples/remote-mcp-functions-dotnet): This set of repositories are quickstart template for building and deploying custom remote MCP (Model Context Protocol) servers using Azure Functions with Python, C# .NET or Node/TypeScript.
168214
@@ -172,7 +218,8 @@ The Samples provides a complete solution that allows developers to:
172218
- Deploy to Azure: Easily deploy to the cloud with a simple azd up command
173219
- Connect from clients: Connect to the MCP server from various clients including VS Code's Copilot agent mode and the MCP Inspector tool
174220

175-
#### Key Features:
221+
### Key Features:
222+
176223
- Security by design: The MCP server is secured using keys and HTTPS
177224
- Authentication options: Supports OAuth using built-in auth and/or API Management
178225
- Network isolation: Allows network isolation using Azure Virtual Networks (VNET)
@@ -188,7 +235,6 @@ The repository includes all necessary configuration files, source code, and infr
188235

189236
- [Azure Remote MCP Functions Node/Typescript](https://github.com/Azure-Samples/remote-mcp-functions-typescript) - Sample implementation of MCP using Azure Functions with Node/TypeScript.
190237

191-
192238
## Key Takeaways
193239

194240
- MCP SDKs provide language-specific tools for implementing robust MCP solutions
85.2 KB
Loading

0 commit comments

Comments
 (0)