Skip to main content
⏳ Estimated read time: 5 min read

StackBuilder MCP Integration

The Model Context Protocol (MCP) server allows AI tools like Claude and VS Code to communicate with and invoke functionalities from the StackGen CLI. Configuring the MCP server involves running the stackgen mcp command and connecting it to your AI tool.

This guide provides step-by-step instructions for Developers and DevOps to set up the StackGen MCP server on their local machines.

StackGen leverages MCP to:

  • Connect to Infrastructure State: Access real-time information about your existing infrastructure.
  • Integrate with External Tools: Connect to monitoring, logging, and management tools.
  • Provide Context-Aware Suggestions: Generate infrastructure recommendations based on current system state.
  • Enable Real-Time Collaboration: Share context between different AI agents and tools.

Key Benefits

The key benefits of integrating StackGen MCP Server are:

  • Real-Time Context: AI models can access current infrastructure state.
  • Tool Integration: Connect to external monitoring, logging, and management systems.
  • Standardized Interface: Consistent way to connect various data sources.
  • Security: Secure, authenticated access to sensitive infrastructure data.

Set Up the StackGen MCP Server

1. Configure the StackGen CLI

Click to view

Before setting up the MCP server, ensure you have the StackGen CLI installed and configured. This is the command-line tool that will run the MCP server.

The MCP server connects to the StackGen cloud service, so you will need a StackGen token. This token authenticates your requests and grants access to your StackGen account.

2. Connect to an AI Tool

Click to view

The MCP server acts as a bridge, allowing your AI tool to call StackGen's capabilities. You can either configure:

  1. Local StackGen MCP Server to run on your machine or,
  2. Connect to a remote StackGen MCP Server.

Let's learn how to configure StackGen MCP Server using these methods in detail.

1. Run a Local StackGen MCP Server

You can start the MCP server locally using the StackGen CLI. The command stackgen mcp will launch the server and listen for incoming requests from your AI tool.

To stop the server, use Ctrl + c on windows or Command + c on macOS.

2. Connecting via a Docker MCP Registry

If you prefer to run the server in a containerized environment, you can use the official MCP Server from the Docker Registry:

stackgen: https://hub.docker.com/mcp/server/stackgen/config

This is especially useful for managing dependencies and ensuring a consistent environment.

3. Integrate with Your AI Tool

Click to view

The final step is to configure your preferred AI tool to connect to the StackGen MCP Server. The method varies depending on the tool you're using. Let's see how you can do that for:

Claude

To add the StackGen MCP server to Claude, use the claude mcp add stackgen command:

claude mcp add stackgen \
--env STACKGEN_URL=https://cloud.stackgen.com \
--env STACKGEN_TOKEN="<STACKGEN_PAT>" \
-s user -- stackgen mcp

This command registers the StackGen server with Claude, providing the necessary environment variables for authentication.

Flags
FlagDescription
claude mcp add stackgenInitiates the process of adding a new MCP server named stackgen.
--env STACKGEN_URL=...Sets the STACKGEN_URL environment variable, specifying the endpoint for the StackGen cloud service.
--env STACKGEN_TOKEN="..."Sets the STACKGEN_TOKEN environment variable, which is crucial for authenticating your requests. For example, https://cloud.stackgen.com.

Replace <STACKGEN_PAT> with your actual token.
-s userThis flag saves the configuration to your user settings, making it available for all your Claude sessions.
-- stackgen mcpSpecifies the executable to run when the server is invoked. In this case, it's the stackgen mcp command.

VS Code

Visual Studio Code provides a dedicated setting for configuring MCP servers. You can add the StackGen MCP server directly to your VS Code settings file. Follow these steps:

  1. Open your VS Code settings by pressing Ctrl + on windows or Cmd + on macOS.

  2. Search for MCP to find the relevant settings.

  3. Click Edit in settings.json to open the settings file directly.

  4. Add the following JSON configuration to your settings.json file:

    {
    "servers": {
    "stackgen-mcp": {
    "type": "sse",
    "url": "https://cloud.stackgen.com/api/mcp/sse",
    "headers": {
    "authorization": "Bearer <STACKGEN_TOKEN>"
    }
    }
    }
    }
    Parameters
    ParameterDescription
    stackgen-mcpUser-defined name for the server. You can choose a descriptive name to easily identify it.
    "type":"sse":Specifies the communication protocol, which is Server-Sent Events (SSE).
    "url": "..."Endpoint URL for the StackGen MCP server.
    "headers": { "authorization": "Bearer <STACKGEN_TOKEN>" }This section includes the authorization header with your StackGen token. Remember to replace <STACKGEN_TOKEN> with your actual token.
  5. After saving the settings.json file, VS Code will automatically detect the new server and make StackGen's functionalities available in its AI-powered features, such as Copilot Chat.

Troubleshooting

Here are the most commonly encountered errors and steps to troubleshoot them:

  • Authentication Issues: Double-check that your STACKGEN_TOKEN is correct and hasn't expired against the right STACKGEN_URL domain.
  • Connection Problems: Ensure your firewall isn't blocking the connection and that the StackGen server URL is accessible from your network.
  • Tool Not Found: If your AI tool can't find the StackGen server, restart the application or the StackGen CLI to ensure the new configuration is loaded.