Skip to content

feat(cli): add initial mcp subcommand in cli to start mcp server#145

Open
Adamkadaban wants to merge 6 commits intomainfrom
mcp
Open

feat(cli): add initial mcp subcommand in cli to start mcp server#145
Adamkadaban wants to merge 6 commits intomainfrom
mcp

Conversation

@Adamkadaban
Copy link
Copy Markdown
Member

Checklist

  • I have added a version label to my PR (e.g., patch, minor, major).
  • I have tested my changes locally and verified they work as expected.
  • I have added relevant tests to cover my changes.
  • I have made any necessary updates to the documentation.
  • I have made any necessary updates to the CLI.
  • I have made any necessary updates to the frontend.

Description

This pull request introduces a new "MCP" (Model Context Protocol) feature to the CLI, enabling users to manage an MCP server for AI assistant integration. It adds commands for starting the server, checking its status, and listing available tools, along with the necessary backend support for these operations. Below are the most important changes grouped by theme:

New MCP Command and Subcommands

  • Added a new mcp command with subcommands: start, status, and tools. These commands allow users to start the MCP server, check its status, and list available tools, respectively. (cli/cmd/mcp/mcp.go, cli/cmd/mcp/start.go, cli/cmd/mcp/status.go, cli/cmd/mcp/tools.go) [1] [2] [3] [4]

MCP Server Implementation

  • Implemented the Server struct in cli/internal/mcp/server.go to manage the MCP server lifecycle and provide functionality for both "stdio" and "SSE" transport modes. It includes methods for registering tools, handling configuration changes, and providing detailed instructions to the server. (cli/internal/mcp/server.go)

Integration with CLI Framework

  • Integrated the mcp command into the CLI by adding it to the root command and ensuring it shares the global configuration. (cli/cmd/root.go) [1] [2] [3]

Logging Enhancements

  • Added new logging functions (Success, Failure, Notice) in cli/internal/logger/logger.go to provide consistent and user-friendly status indicators for CLI operations. (cli/internal/logger/logger.go)

Dependency Updates

  • Updated go.mod to include new dependencies required for the MCP server, such as github.com/mark3labs/mcp-go and github.com/spf13/cast. (cli/go.mod) [1] [2]

Examples in Claude Code

image image

Examples in VSCode

image image

Fixes: #141

Copilot AI review requested due to automatic review settings July 26, 2025 08:18
@Adamkadaban Adamkadaban added the minor Increment the minor version when merged label Jul 26, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new MCP (Model Context Protocol) feature to the OpenLabs CLI, enabling AI assistants to interact with OpenLabs services through standardized protocol tools. The implementation includes server functionality, command-line interface, and comprehensive tool definitions for managing ranges, blueprints, and cloud credentials.

  • Adds mcp command with start, status, and tools subcommands for managing the MCP server
  • Implements MCP server with support for both stdio and SSE transport modes
  • Provides 14 tools covering range management, blueprint operations, cloud credentials, and authentication
  • Enhances logging with new status indicator functions and table formatting improvements

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cli/cmd/mcp/*.go New MCP command structure with start, status, and tools subcommands
cli/internal/mcp/*.go Core MCP server implementation, tool definitions, and request handlers
cli/internal/output/table.go Enhanced table formatting with MCP-specific display function
cli/internal/logger/logger.go Added status logging functions with consistent indicators
cli/go.mod Updated dependencies for MCP functionality
cli/cmd/root.go Integration of MCP commands into CLI structure
Comments suppressed due to low confidence (2)

cli/internal/output/table.go:247

  • [nitpick] The function name getStructFieldValue is ambiguous. Consider renaming to extractStructFieldByName or getFieldValueByName to better indicate it searches for fields by name.
func getStructFieldValue(val reflect.Value, fieldName string) string {

cli/internal/mcp/server.go:53

  • [nitpick] The function name reloadConfigIfChanged doesn't clearly indicate what constitutes a 'change'. Consider renaming to reloadConfigIfTokenChanged to be more specific about what triggers the reload.
func (s *Server) reloadConfigIfChanged() bool {

@Adamkadaban
Copy link
Copy Markdown
Member Author

Adamkadaban commented Jul 26, 2025

I should probably change the prompt to say creds don't go through an llm, instead of saying it won't go over the protocol. Probably more accurate + relevant

should do the same for cloud secrets. maybe consider making prompts shorter to save context

Also need to make Docs. TODO

Also need to look into sse vs streamable http for transport

…users know sending credentials to llm is potentially insecure
return nil
}

func (s *Server) handleListRanges(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is Go convention, but why would we want to have an error as a return type here if we only ever return nil for the error in this function?

return mcp.NewToolResultError("Missing or invalid aws_secret_key parameter"), nil
}

err = s.client.UpdateAWSSecrets(accessKey, secretKey)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably will need to be updated because of the secret's endpoint changes.

return mcp.NewToolResultError("Missing or invalid azure_subscription_id parameter"), nil
}

err = s.client.UpdateAzureSecrets(clientID, clientSecret, tenantID, subscriptionID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also probably need to be updated to reflect the updated secrets endpoint.

Copy link
Copy Markdown
Member

@alexchristy alexchristy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! It was interesting to see how the MCP server works and how the data and prompts are built. This was also a good refresher on go.

s.mcpServer,
server.WithSSEEndpoint("/sse"),
server.WithMessageEndpoint("/message"),
server.WithBaseURL(fmt.Sprintf("http://localhost%s", port)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this break if addr = '127.0.0.1:9000'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Increment the minor version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenLabs MCP

3 participants