-
Notifications
You must be signed in to change notification settings - Fork 20
BYOC mcp #1409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
BYOC mcp #1409
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
027ee78
spike on byoc mcp
KevyVo 8a65c04
set defang env
KevyVo 97f2804
Able to set provider
KevyVo 52f4a16
Refactor prompt
KevyVo b24443c
Merge remote-tracking branch 'origin/main' into kevin/prompts
KevyVo bfe1236
Missing region env
KevyVo 7adb82f
Added CheckProviderConfigured and mod CanIUseProvider
KevyVo 0049a2e
prompts
KevyVo d968066
cleanup
KevyVo 542109d
Replace the vendorHash in cli.nix
KevyVo 594962f
Remove unused code
KevyVo 88ed489
Change role response
KevyVo ddca90d
Add source
KevyVo ebc6a9c
Merge branch 'main' into kevin/prompts
KevyVo cb2a64a
Apply suggestions from code review
lionello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package prompts | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
"github.com/DefangLabs/defang/src/pkg/cli" | ||
"github.com/DefangLabs/defang/src/pkg/cli/client" | ||
"github.com/DefangLabs/defang/src/pkg/mcp/tools" | ||
"github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
|
||
func setupAWSBYOPrompt(s *server.MCPServer, cluster string, providerId *client.ProviderID) { | ||
awsBYOCPrompt := mcp.NewPrompt("AWS Setup", | ||
mcp.WithPromptDescription("Setup for AWS"), | ||
|
||
mcp.WithArgument("AWS_Credential", | ||
mcp.ArgumentDescription("Your AWS Access Key ID or AWS Profile Name"), | ||
mcp.RequiredArgument(), | ||
), | ||
|
||
mcp.WithArgument("AWS_SECRET_ACCESS_KEY", | ||
mcp.ArgumentDescription("Your AWS Secret Access Key"), | ||
), | ||
|
||
mcp.WithArgument("AWS_REGION", | ||
mcp.ArgumentDescription("Your AWS Region"), | ||
), | ||
) | ||
|
||
s.AddPrompt(awsBYOCPrompt, func(ctx context.Context, req mcp.GetPromptRequest) (*mcp.GetPromptResult, error) { | ||
// Can never be nil or empty due to RequiredArgument | ||
awsID := req.Params.Arguments["AWS_Credential"] | ||
if isValidAWSKey(awsID) { | ||
err := os.Setenv("AWS_ACCESS_KEY_ID", awsID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
awsSecret := getStringArg(req.Params.Arguments, "AWS_SECRET_ACCESS_KEY", "") | ||
region := getStringArg(req.Params.Arguments, "AWS_REGION", "") | ||
|
||
if awsSecret == "" { | ||
return nil, errors.New("AWS_SECRET_ACCESS_KEY is required") | ||
} | ||
|
||
err = os.Setenv("AWS_SECRET_ACCESS_KEY", awsSecret) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if region == "" { | ||
return nil, errors.New("AWS_REGION is required") | ||
} | ||
|
||
err = os.Setenv("AWS_REGION", region) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
err := os.Setenv("AWS_PROFILE", awsID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
fabric, err := cli.Connect(ctx, cluster) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = tools.CheckProviderConfigured(ctx, fabric, client.ProviderAWS, "", 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
*providerId = client.ProviderAWS | ||
|
||
//FIXME: Should not be setting both the global and env var | ||
err = os.Setenv("DEFANG_PROVIDER", "aws") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &mcp.GetPromptResult{ | ||
Description: "AWS BYOC Setup Complete", | ||
Messages: []mcp.PromptMessage{ | ||
{ | ||
Role: mcp.RoleUser, | ||
Content: mcp.NewTextContent(postPrompt), | ||
}, | ||
}, | ||
}, nil | ||
}) | ||
} | ||
|
||
// Check if the provided AWS access key ID is valid | ||
// https://medium.com/@TalBeerySec/a-short-note-on-aws-key-id-f88cc4317489 | ||
func isValidAWSKey(key string) bool { | ||
// Define accepted AWS access key prefixes | ||
acceptedPrefixes := map[string]bool{ | ||
"ABIA": true, | ||
"ACCA": true, | ||
"AGPA": true, | ||
"AIDA": true, | ||
"AKPA": true, | ||
"AKIA": true, | ||
"ANPA": true, | ||
"ANVA": true, | ||
"APKA": true, | ||
"AROA": true, | ||
"ASCA": true, | ||
"ASIA": true, | ||
} | ||
|
||
if len(key) < 16 { | ||
return false | ||
} | ||
|
||
prefix := key[:4] | ||
_, ok := acceptedPrefixes[prefix] | ||
if !ok { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package prompts | ||
|
||
const postPrompt = "Can you deploy my application now." | ||
lionello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
func getStringArg(args map[string]string, key, defaultValue string) string { | ||
if val, exists := args[key]; exists { | ||
return val | ||
} | ||
return defaultValue | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package prompts | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/DefangLabs/defang/src/pkg/cli" | ||
"github.com/DefangLabs/defang/src/pkg/cli/client" | ||
"github.com/DefangLabs/defang/src/pkg/mcp/tools" | ||
"github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
|
||
func setupGCPBYOPrompt(s *server.MCPServer, cluster string, providerId *client.ProviderID) { | ||
gcpBYOPrompt := mcp.NewPrompt("GCP Setup", | ||
mcp.WithPromptDescription("Setup for GCP"), | ||
|
||
mcp.WithArgument("GCP_PROJECT_ID", | ||
mcp.ArgumentDescription("Your GCP Project ID"), | ||
mcp.RequiredArgument(), | ||
), | ||
) | ||
|
||
s.AddPrompt(gcpBYOPrompt, func(ctx context.Context, req mcp.GetPromptRequest) (*mcp.GetPromptResult, error) { | ||
// Can never be nil or empty due to RequiredArgument | ||
projectID := req.Params.Arguments["GCP_PROJECT_ID"] | ||
|
||
err := os.Setenv("GCP_PROJECT_ID", projectID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fabric, err := cli.Connect(ctx, cluster) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = tools.CheckProviderConfigured(ctx, fabric, client.ProviderGCP, "", 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
*providerId = client.ProviderGCP | ||
|
||
//FIXME: Should not be setting both the global var and env var | ||
err = os.Setenv("DEFANG_PROVIDER", "gcp") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &mcp.GetPromptResult{ | ||
Description: "GCP BYOC Setup Complete", | ||
Messages: []mcp.PromptMessage{ | ||
{ | ||
Role: mcp.RoleUser, | ||
Content: mcp.NewTextContent(postPrompt), | ||
}, | ||
}, | ||
}, nil | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package prompts | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/DefangLabs/defang/src/pkg/cli/client" | ||
"github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
|
||
func setupPlaygroundPrompt(s *server.MCPServer, providerId *client.ProviderID) { | ||
playgroundPrompt := mcp.NewPrompt("Playground Setup", | ||
mcp.WithPromptDescription("Setup for Playground"), | ||
) | ||
|
||
s.AddPrompt(playgroundPrompt, func(ctx context.Context, req mcp.GetPromptRequest) (*mcp.GetPromptResult, error) { | ||
*providerId = client.ProviderDefang | ||
|
||
//FIXME: Should not be setting both the global and env var | ||
err := os.Setenv("DEFANG_PROVIDER", "defang") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &mcp.GetPromptResult{ | ||
Description: "Defang playground Setup Complete", | ||
Messages: []mcp.PromptMessage{ | ||
{ | ||
Role: mcp.RoleUser, | ||
Content: mcp.NewTextContent(postPrompt), | ||
}, | ||
}, | ||
}, nil | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package prompts | ||
|
||
import ( | ||
"github.com/DefangLabs/defang/src/pkg/cli/client" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
|
||
// SetupPrompts configures and adds all prompts to the MCP server | ||
func SetupPrompts(s *server.MCPServer, cluster string, providerId *client.ProviderID) { | ||
//AWS BYOC | ||
setupAWSBYOPrompt(s, cluster, providerId) | ||
|
||
//GCP BYOC | ||
setupGCPBYOPrompt(s, cluster, providerId) | ||
|
||
//Playground | ||
setupPlaygroundPrompt(s, providerId) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.