|
| 1 | +--- |
| 2 | +title: MCP |
| 3 | +description: Model Context Protocol (MCP) server with built-in tools to allow users to deploy with Defang through a supported IDE. |
| 4 | +sidebar-position: 200 |
| 5 | +--- |
| 6 | + |
| 7 | +# Model Context Protocol (MCP) |
| 8 | + |
| 9 | +Defang has a [Model Context Protocol (MCP) server](https://github.com/DefangLabs/defang) with built-in tools to allow users to deploy and manage cloud services through a |
| 10 | +supported IDE. |
| 11 | + |
| 12 | +For more detail on MCP architecture, visit the [official MCP documentation](https://modelcontextprotocol.io/introduction). |
| 13 | + |
| 14 | +### Overview |
| 15 | + |
| 16 | +An MCP server enhances the functionality of AI agents by enabling them to use external resources and tools to create responses or perform tasks (e.g. integrate with Defang). In the case of Defang's MCP Server, you can use deploy and manage your services by asking an AI agent to do so in an IDE. |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +To run this server, you will need to install the [Defang CLI](/docs/getting-started). Then, you can run: |
| 21 | + |
| 22 | +```bash |
| 23 | +defang mcp --client=<your-ide> |
| 24 | +``` |
| 25 | + |
| 26 | +This sets up the MCP server to connect with your IDE. |
| 27 | + |
| 28 | +## Supported IDEs |
| 29 | + |
| 30 | +### Cursor |
| 31 | + |
| 32 | +``` |
| 33 | +defang mcp --client=cursor |
| 34 | +``` |
| 35 | + |
| 36 | +### Windsurf |
| 37 | + |
| 38 | +``` |
| 39 | +defang mcp --client=windsurf |
| 40 | +``` |
| 41 | + |
| 42 | +### VSCode / VSCode Insiders |
| 43 | + |
| 44 | +``` |
| 45 | +defang mcp --client=vscode |
| 46 | +``` |
| 47 | + |
| 48 | +### Claude Desktop |
| 49 | + |
| 50 | +(While this is not an IDE in the traditional sense, it can support MCP servers.) |
| 51 | + |
| 52 | +``` |
| 53 | +defang mcp --client=claude |
| 54 | +``` |
| 55 | + |
| 56 | +## MCP Tools |
| 57 | + |
| 58 | +Below are the tools available in the Defang MCP Server. |
| 59 | + |
| 60 | +### `deploy` |
| 61 | + |
| 62 | +The `deploy` tool scans your project directory for Dockerfiles and `compose.yaml` files, then deploys the detected service(s) using Defang. You can monitor the deployment process in the Defang Portal. |
| 63 | + |
| 64 | +### `destroy` |
| 65 | + |
| 66 | +Given a project name or directory, the `destroy` tool identifies any services deployed with Defang and terminates them. If no services are found, it will display an appropriate message. |
| 67 | + |
| 68 | +### `login` |
| 69 | + |
| 70 | +The `login` tool will open a browser to the Portal to authenticate to Defang. Once you are logged in, a session token is stored, and you will not need to log in again until the session expires or you manually log out. |
| 71 | + |
| 72 | +### `services` |
| 73 | + |
| 74 | +The `services` tool displays the details of all your services that are currently deployed with Defang. It shows the Service Name, Deployment ID, Public URL and Service Status. If there are no services found, it will display an appropriate message. |
| 75 | + |
| 76 | +:::info |
| 77 | +This page is a guide to the Defang MCP Server detailing its usage, installation, and tools. If you are looking for an example of how you can deploy a MCP project with Defang, please instead refer to our [MCP sample application](https://github.com/DefangLabs/samples/tree/main/samples/mcp). |
| 78 | +::: |
| 79 | + |
| 80 | +## Example Prompts |
| 81 | + |
| 82 | +Let's say you are using an IDE with an AI agent. After connecting the Defang MCP Server to your IDE using an installation method, you can type in prompts in your chat to invoke the AI agent to use an MCP tool(s). |
| 83 | + |
| 84 | +In your IDE with your project open, you can ask the AI agent: |
| 85 | + |
| 86 | +``` |
| 87 | +can you deploy this to defang? |
| 88 | +``` |
| 89 | + |
| 90 | +``` |
| 91 | +please destroy this project. |
| 92 | +``` |
| 93 | + |
| 94 | +``` |
| 95 | +am I logged in to defang? |
| 96 | +``` |
| 97 | + |
| 98 | +``` |
| 99 | +what services do I have? |
| 100 | +``` |
| 101 | + |
| 102 | +You can also choose to specify a project name or project directory if you do not have the project open: |
| 103 | + |
| 104 | +``` |
| 105 | +deploy this with defang /Users/yourname/Documents/project1 |
| 106 | +``` |
| 107 | + |
| 108 | +``` |
| 109 | +do I have a service called project1 |
| 110 | +``` |
0 commit comments