-
Notifications
You must be signed in to change notification settings - Fork 211
feat: add dapr mcpservers cli cmd #1628
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| Copyright 2026 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/kubernetes" | ||
| "github.com/dapr/cli/pkg/print" | ||
|
|
||
| meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| var ( | ||
| mcpserversName string | ||
| mcpserversOutputFormat string | ||
| ) | ||
|
|
||
| var McpserversCmd = &cobra.Command{ | ||
| Use: "mcpservers", | ||
| Short: "List all Dapr MCPServer resources. Supported platforms: Kubernetes", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| if kubernetesMode { | ||
| if allNamespaces { | ||
| resourceNamespace = meta_v1.NamespaceAll | ||
| } else if resourceNamespace == "" { | ||
| resourceNamespace = meta_v1.NamespaceAll | ||
| } | ||
| err := kubernetes.PrintMCPServers(mcpserversName, resourceNamespace, mcpserversOutputFormat) | ||
| if err != nil { | ||
| print.FailureStatusEvent(os.Stderr, err.Error()) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| }, | ||
| PostRun: func(cmd *cobra.Command, args []string) { | ||
| kubernetes.CheckForCertExpiry() | ||
| }, | ||
| Example: ` | ||
| # List all Dapr MCPServer resources in Kubernetes mode | ||
| dapr mcpservers -k | ||
|
|
||
| # List MCPServer resources in a specific namespace | ||
| dapr mcpservers -k --namespace default | ||
|
|
||
| # Print a specific MCPServer resource | ||
| dapr mcpservers -k -n my-mcp-server | ||
|
|
||
| # List MCPServer resources across all namespaces | ||
| dapr mcpservers -k --all-namespaces | ||
|
|
||
| # Output as JSON | ||
| dapr mcpservers -k -o json | ||
| `, | ||
| } | ||
|
|
||
| func init() { | ||
| McpserversCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If true, list all Dapr MCPServer resources in all namespaces") | ||
| McpserversCmd.Flags().StringVarP(&mcpserversName, "name", "n", "", "The MCPServer name to be printed (optional)") | ||
| McpserversCmd.Flags().StringVarP(&resourceNamespace, "namespace", "", "", "List MCPServer resources in a specific Kubernetes namespace") | ||
| McpserversCmd.Flags().StringVarP(&mcpserversOutputFormat, "output", "o", "list", "Output format (options: json or yaml or list)") | ||
| McpserversCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "List all Dapr MCPServer resources in a Kubernetes cluster") | ||
| McpserversCmd.Flags().BoolP("help", "h", false, "Print this help message") | ||
| McpserversCmd.MarkFlagRequired("kubernetes") | ||
| RootCmd.AddCommand(McpserversCmd) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,153 @@ | ||||||||||||||
| /* | ||||||||||||||
| Copyright 2026 The Dapr Authors | ||||||||||||||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
| you may not use this file except in compliance with the License. | ||||||||||||||
| You may obtain a copy of the License at | ||||||||||||||
| http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
| Unless required by applicable law or agreed to in writing, software | ||||||||||||||
| distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
| See the License for the specific language governing permissions and | ||||||||||||||
| limitations under the License. | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| package kubernetes | ||||||||||||||
|
|
||||||||||||||
| import ( | ||||||||||||||
| "io" | ||||||||||||||
| "os" | ||||||||||||||
| "sort" | ||||||||||||||
| "strings" | ||||||||||||||
|
|
||||||||||||||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||||||||||||||
| meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||
|
|
||||||||||||||
| "github.com/dapr/cli/pkg/age" | ||||||||||||||
| "github.com/dapr/cli/utils" | ||||||||||||||
| v1alpha1 "github.com/dapr/dapr/pkg/apis/mcpserver/v1alpha1" | ||||||||||||||
|
Check failure on line 27 in pkg/kubernetes/mcpservers.go
|
||||||||||||||
| "github.com/dapr/dapr/pkg/client/clientset/versioned" | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| // MCPServerOutput represents an MCPServer resource for table output. | ||||||||||||||
| type MCPServerOutput struct { | ||||||||||||||
| Namespace string `csv:"Namespace"` | ||||||||||||||
| Name string `csv:"Name"` | ||||||||||||||
| Transport string `csv:"TRANSPORT"` | ||||||||||||||
| URL string `csv:"URL"` | ||||||||||||||
| Scopes string `csv:"SCOPES"` | ||||||||||||||
| Created string `csv:"CREATED"` | ||||||||||||||
| Age string `csv:"AGE"` | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // mcpServerDetailedOutput is used for JSON/YAML output. | ||||||||||||||
| type mcpServerDetailedOutput struct { | ||||||||||||||
| Name string `json:"name"` | ||||||||||||||
| Namespace string `json:"namespace"` | ||||||||||||||
| Spec v1alpha1.MCPServerSpec `json:"spec"` | ||||||||||||||
|
Comment on lines
+44
to
+46
|
||||||||||||||
| Name string `json:"name"` | |
| Namespace string `json:"namespace"` | |
| Spec v1alpha1.MCPServerSpec `json:"spec"` | |
| Name string `json:"name" yaml:"name"` | |
| Namespace string `json:"namespace" yaml:"namespace"` | |
| Spec v1alpha1.MCPServerSpec `json:"spec" yaml:"spec"` |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a dependency on the MCPServer typed client (client.MCPServerV1alpha1()), but this repo’s current github.com/dapr/dapr module version may not include the generated clientset for MCPServer yet (as noted in the PR description). Please update go.mod (or add a temporary replace) to a dapr/dapr commit that contains the MCPServer clientset changes, otherwise this will not compile in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go naming for initialisms typically keeps them fully-capitalized (e.g., MTLSCmd). Consider renaming
McpserversCmdtoMCPServersCmd(and file-local references accordingly) to match the established command naming style.