|
| 1 | +# MCP |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-mcp-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This is a sample of an MCP (Model Context Protocol) chatbot application built with Next.js, Python, and Anthropic Claude, deployed using Defang. |
| 6 | + |
| 7 | +This example uses Docker's [`mcp/time`](https://hub.docker.com/r/mcp/time) image as a base for the MCP server (with MCP tools included), but it can be adapted to use any of the Docker [MCP images](https://hub.docker.com/u/mcp). |
| 8 | + |
| 9 | +### How It Works |
| 10 | + |
| 11 | +The [MCP client](https://modelcontextprotocol.io/quickstart/client) is written in Python and ran in a `venv` virtual environment. The MCP server is provided by the Docker `mcp/time` image. The MCP server communicates with the MCP client in a Quart app (i.e. Asynchronous Server Gateway Interface (ASGI) version of Flask) through the `stdio` transport method, as seen in `/mcp-server/main.py`. For more on MCP transport methods, see [here](https://modelcontextprotocol.io/docs/concepts/transports). |
| 12 | + |
| 13 | +The UI (User Interface) and web server are built in Next.js (see `/ui/src/app`). The web server includes a forwarding action to connect to the MCP client. |
| 14 | + |
| 15 | +Here's a breakdown of what happens when you interact with the UI: |
| 16 | +1. When a user submits a query to the chatbot, the browser sends a request to the Next.js web server. |
| 17 | +2. The Next.js web server will forward this request to the MCP client via a REST endpoint. |
| 18 | +3. The MCP client processes the request by interacting with the Anthropic (Claude) API and tools available through the MCP server. |
| 19 | +4. Once the response is generated, it is sent back to the Next.js web server and displayed to the user in the UI. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 24 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 25 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 26 | + |
| 27 | +## Development |
| 28 | + |
| 29 | +To run the application locally, you can use the following command: |
| 30 | + |
| 31 | +```bash |
| 32 | +docker compose up --build |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration |
| 36 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
| 37 | + |
| 38 | +> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you. |
| 39 | +
|
| 40 | +### `ANTHROPIC_API_KEY` |
| 41 | +An API key for accessing the [Anthropic Claude API](https://docs.anthropic.com/en/api/getting-started). |
| 42 | +```bash |
| 43 | +defang config set ANTHROPIC_API_KEY |
| 44 | +``` |
| 45 | + |
| 46 | +## Deployment |
| 47 | + |
| 48 | +> [!NOTE] |
| 49 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 50 | +
|
| 51 | +### Defang Playground |
| 52 | + |
| 53 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 54 | +```bash |
| 55 | +defang compose up |
| 56 | +``` |
| 57 | + |
| 58 | +### BYOC |
| 59 | + |
| 60 | +If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud). |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +Title: MCP |
| 65 | + |
| 66 | +Short Description: An MCP (Model Context Protocol) chatbot assistant built with Next.js, Python, and Anthropic Claude. |
| 67 | + |
| 68 | +Tags: MCP, Next.js, Python, Quart, Claude, AI, Anthropic, TypeScript, React, JavaScript |
| 69 | + |
| 70 | +Languages: nodejs |
0 commit comments