|
| 1 | +# Case Study: Connecting to the Microsoft Learn Docs MCP Server from a Client |
| 2 | + |
| 3 | +Have you ever found yourself juggling between documentation sites, Stack Overflow, and endless search engine tabs, all while trying to solve a problem in your code? Maybe you keep a second monitor just for docs, or you’re constantly alt-tabbing between your IDE and a browser. Wouldn’t it be better if you could bring the documentation right into your workflow—integrated into your apps, your IDE, or even your own custom tools? In this case study, we’ll explore how to do exactly that by connecting directly to the Microsoft Learn Docs MCP server from your own client application. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Modern development is more than just writing code—it’s about finding the right information at the right time. Documentation is everywhere, but it’s rarely where you need it most: inside your tools and workflows. By integrating documentation retrieval directly into your applications, you can save time, reduce context switching, and boost productivity. In this section, we’ll show you how to connect a client to the Microsoft Learn Docs MCP server, so you can access real-time, context-aware documentation without ever leaving your app. |
| 8 | + |
| 9 | +We’ll walk through the process of establishing a connection, sending a request, and handling streaming responses efficiently. This approach not only streamlines your workflow but also opens the door to building smarter, more helpful developer tools. |
| 10 | + |
| 11 | +## Learning Objectives |
| 12 | + |
| 13 | +Why are we doing this? Because the best developer experiences are those that remove friction. Imagine a world where your code editor, chatbot, or web app can answer your documentation questions instantly, using the latest content from Microsoft Learn. By the end of this chapter, you’ll know how to: |
| 14 | + |
| 15 | +- Understand the basics of MCP server-client communication for documentation |
| 16 | +- Implement a console or web application to connect to the Microsoft Learn Docs MCP server |
| 17 | +- Use streaming HTTP clients for real-time documentation retrieval |
| 18 | +- Log and interpret documentation responses in your application |
| 19 | + |
| 20 | +You’ll see how these skills can help you build tools that are not just reactive, but truly interactive and context-aware. |
| 21 | + |
| 22 | +## Scenario 1 - Real-Time Documentation Retrieval with MCP |
| 23 | + |
| 24 | +In this scenario, we’ll show you how to connect a client to the Microsoft Learn Docs MCP server, so you can access real-time, context-aware documentation without ever leaving your app. |
| 25 | + |
| 26 | +Let’s put this into practice. Your task is to write an app that connects to the Microsoft Learn Docs MCP server, invokes the `microsoft_docs_search` tool, and logs the streaming response to the console. |
| 27 | + |
| 28 | +### Why this approach? |
| 29 | +Because it’s the foundation for building more advanced integrations—whether you want to power a chatbot, an IDE extension, or a web dashboard. |
| 30 | + |
| 31 | +You'll find the code and instructions for this scenario in the [`solution`](./solution/README.md) folder within this case study. The steps will guide you through setting up the connection: |
| 32 | +- Use the official MCP SDK and streamable HTTP client for connection |
| 33 | +- Call the `microsoft_docs_search` tool with a query parameter to retrieve documentation |
| 34 | +- Implement proper logging and error handling |
| 35 | +- Create an interactive console interface to allow users to enter multiple search queries |
| 36 | + |
| 37 | +This scenario demonstrates how to: |
| 38 | +- Connect to the Docs MCP server |
| 39 | +- Send a query |
| 40 | +- Parse and print the results |
| 41 | + |
| 42 | +Here’s what running the solution might look like: |
| 43 | + |
| 44 | +``` |
| 45 | +Prompt> What is Azure Key Vault? |
| 46 | +Answer> Azure Key Vault is a cloud service for securely storing and accessing secrets. ... |
| 47 | +``` |
| 48 | + |
| 49 | +Below is a minimal sample solution. The full code and details are available in the solution folder. |
| 50 | + |
| 51 | +<details> |
| 52 | +<summary>Python</summary> |
| 53 | + |
| 54 | +```python |
| 55 | +import asyncio |
| 56 | +from mcp.client.streamable_http import streamablehttp_client |
| 57 | +from mcp import ClientSession |
| 58 | + |
| 59 | +async def main(): |
| 60 | + async with streamablehttp_client("https://learn.microsoft.com/api/mcp") as (read_stream, write_stream, _): |
| 61 | + async with ClientSession(read_stream, write_stream) as session: |
| 62 | + await session.initialize() |
| 63 | + result = await session.call_tool("microsoft_docs_search", {"query": "Azure Functions best practices"}) |
| 64 | + print(result.content) |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + asyncio.run(main()) |
| 68 | +``` |
| 69 | + |
| 70 | +- For the complete implementation and logging, see [`scenario1.py`](./solution/python/scenario1.py). |
| 71 | +- For installation and usage instructions, see the [`README.md`](./solution/python/README.md) file in the same folder. |
| 72 | +</details> |
| 73 | + |
| 74 | + |
| 75 | +## Scenario 2 - Interactive Study Plan Generator Web App with MCP |
| 76 | + |
| 77 | +In this scenario, you’ll learn how to integrate Docs MCP into a web development project. The goal is to enable users to search Microsoft Learn documentation directly from a web interface, making documentation instantly accessible within your app or site. |
| 78 | + |
| 79 | +You’ll see how to: |
| 80 | +- Set up a web app |
| 81 | +- Connect to the Docs MCP server |
| 82 | +- Handle user input and display results |
| 83 | + |
| 84 | +Here’s what running the solution might look like: |
| 85 | + |
| 86 | +``` |
| 87 | +User> I want to learn about AI102 - so suggest the roadmap to get it started from learn for 6 weeks |
| 88 | +
|
| 89 | +Assistant> Here’s a detailed 6-week roadmap to start your preparation for the AI-102: Designing and Implementing a Microsoft Azure AI Solution certification, using official Microsoft resources and focusing on exam skills areas: |
| 90 | +
|
| 91 | +--- |
| 92 | +## Week 1: Introduction & Fundamentals |
| 93 | +- **Understand the Exam**: Review the [AI-102 exam skills outline](https://learn.microsoft.com/en-us/credentials/certifications/exams/ai-102/). |
| 94 | +- **Set up Azure**: Sign up for a free Azure account if you don't have one. |
| 95 | +- **Learning Path**: [Introduction to Azure AI services](https://learn.microsoft.com/en-us/training/modules/intro-to-azure-ai/) |
| 96 | +- **Focus**: Get familiar with Azure portal, AI capabilities, and necessary tools. |
| 97 | +
|
| 98 | +....more weeks of the roadmap... |
| 99 | +
|
| 100 | +Let me know if you want module-specific recommendations or need more customized weekly tasks! |
| 101 | +``` |
| 102 | + |
| 103 | +Below is a minimal sample solution. The full code and details are available in the solution folder. |
| 104 | + |
| 105 | +<details> |
| 106 | +<summary>Python (Chainlit)</summary> |
| 107 | + |
| 108 | +Chainlit is a framework for building conversational AI web apps. It makes it easy to create interactive chatbots and assistants that can call MCP tools and display results in real time. It’s ideal for rapid prototyping and user-friendly interfaces. |
| 109 | + |
| 110 | +```python |
| 111 | +import chainlit as cl |
| 112 | +import requests |
| 113 | + |
| 114 | +MCP_URL = "https://learn.microsoft.com/api/mcp" |
| 115 | + |
| 116 | +@cl.on_message |
| 117 | +def handle_message(message): |
| 118 | + query = {"question": message} |
| 119 | + response = requests.post(MCP_URL, json=query) |
| 120 | + if response.ok: |
| 121 | + result = response.json() |
| 122 | + cl.Message(content=result.get("answer", "No answer found.")).send() |
| 123 | + else: |
| 124 | + cl.Message(content="Error: " + response.text).send() |
| 125 | +``` |
| 126 | + |
| 127 | +- For the complete implementation, see [`scenario2.py`](./solution/python/scenario2.py). |
| 128 | +- For setup and running instructions, see the [`README.md`](./solution/python/README.md). |
| 129 | +</details> |
| 130 | + |
| 131 | + |
| 132 | +## Scenario 3: In-Editor Docs with MCP Server in VS Code |
| 133 | + |
| 134 | +If you want to get Microsoft Learn Docs directly inside your VS Code (instead of switching browser tabs), you can use the MCP server in your editor. This allows you to: |
| 135 | +- Search and read docs in VS Code without leaving your coding environment. |
| 136 | +- Reference documentation and insert links directly into your README or course files. |
| 137 | +- Leverage GitHub Copilot and MCP together for a seamless, AI-powered documentation workflow. |
| 138 | + |
| 139 | +**You'll see how to:** |
| 140 | +- Add a valid `.vscode/mcp.json` file to your workspace root (see example below). |
| 141 | +- Open the MCP panel or use the command palette in VS Code to search and insert docs. |
| 142 | +- Reference documentation directly in your markdown files as you work. |
| 143 | +- Combine this workflow with GitHub Copilot for even greater productivity. |
| 144 | + |
| 145 | +Here’s a example of how to set up the MCP server in VS Code: |
| 146 | + |
| 147 | +```json |
| 148 | +{ |
| 149 | + "servers": { |
| 150 | + "LearnDocsMCP": { |
| 151 | + "url": "https://learn.microsoft.com/api/mcp" |
| 152 | + } |
| 153 | + } |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +</details> |
| 158 | + |
| 159 | +> For a detailed walkthrough with screenshots and step-by-step guide, see [`README.md`](./solution/scenario3/README.md). |
| 160 | +
|
| 161 | +This approach is ideal for anyone building technical courses, writing documentation, or developing code with frequent reference needs. |
| 162 | + |
| 163 | +## Key Takeaways |
| 164 | + |
| 165 | +Integrating documentation directly into your tools isn’t just a convenience—it’s a game changer for productivity. By connecting to the Microsoft Learn Docs MCP server from your client, you can: |
| 166 | + |
| 167 | +- Eliminate context switching between your code and documentation |
| 168 | +- Retrieve up-to-date, context-aware docs in real time |
| 169 | +- Build smarter, more interactive developer tools |
| 170 | + |
| 171 | +These skills will help you create solutions that are not only efficient, but also delightful to use. |
| 172 | + |
| 173 | +## Additional Resources |
| 174 | + |
| 175 | +To deepen your understanding, explore these official resources: |
| 176 | + |
| 177 | +- [Microsoft Learn Docs MCP Server (GitHub)](https://github.com/MicrosoftDocs/mcp) |
| 178 | +- [Get started with Azure MCP Server (mcp-python)](https://learn.microsoft.com/en-us/azure/developer/azure-mcp-server/get-started#create-the-python-app) |
| 179 | +- [What is the Azure MCP Server?](https://learn.microsoft.com/en-us/azure/developer/azure-mcp-server/) |
| 180 | +- [Model Context Protocol (MCP) Introduction](https://modelcontextprotocol.io/introduction) |
| 181 | +- [Add plugins from a MCP Server (Python)](https://learn.microsoft.com/en-us/semantic-kernel/concepts/plugins/adding-mcp-plugins) |
0 commit comments