-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add MCPServer resource #2796
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
Open
jonburdo
wants to merge
1
commit into
RedHatQE:main
Choose a base branch
from
jonburdo:mcp-server-resource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Binary file not shown.
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,117 @@ | ||
| # Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/class_generator/README.md | ||
|
|
||
|
|
||
| from typing import Any | ||
|
|
||
| from ocp_resources.exceptions import MissingRequiredArgumentError | ||
| from ocp_resources.resource import NamespacedResource | ||
|
|
||
|
|
||
| class MCPServer(NamespacedResource): | ||
| """ | ||
| MCPServer runs a Model Context Protocol (MCP) server in Kubernetes. | ||
|
|
||
| MCPServer creates and manages a Deployment, Service, and NetworkPolicy to run an MCP server from a | ||
| container image. The MCP server exposes tools, resources, and prompts that AI applications | ||
| can use via the Model Context Protocol. | ||
|
|
||
| Example: | ||
|
|
||
| apiVersion: mcp.x-k8s.io/v1alpha1 | ||
| kind: MCPServer | ||
| metadata: | ||
| name: example | ||
| spec: | ||
| source: | ||
| type: ContainerImage | ||
| containerImage: | ||
| ref: example-mcp-image | ||
| config: | ||
| port: 8080 | ||
|
|
||
| The controller manages Deployment, Service, and NetworkPolicy resources with the same name as the MCPServer, | ||
| using ownerReferences to establish ownership. The controller will reject updates to resources | ||
| owned by other controllers or resources with no controller owner (to prevent silent overwrites | ||
| of manually-created resources), but will adopt orphaned resources from a deleted MCPServer | ||
| with the same name to enable seamless recreation. | ||
| """ | ||
|
|
||
| api_group: str = NamespacedResource.ApiGroup.MCP_X_K8S_IO | ||
|
|
||
| def __init__( | ||
| self, | ||
| config: dict[str, Any] | None = None, | ||
| extra_annotations: dict[str, Any] | None = None, | ||
| extra_labels: dict[str, Any] | None = None, | ||
| mcp: dict[str, Any] | None = None, | ||
| runtime: dict[str, Any] | None = None, | ||
| source: dict[str, Any] | None = None, | ||
| **kwargs: Any, | ||
| ) -> None: | ||
| r""" | ||
| Args: | ||
| config (dict[str, Any]): Config is a required field that defines how the MCP server should be | ||
| configured when it runs. This includes runtime settings such as | ||
| the server port, command-line arguments, environment variables, | ||
| and storage mounts. | ||
|
|
||
| extra_annotations (dict[str, Any]): ExtraAnnotations are applied to the Deployment metadata, PodTemplate | ||
| metadata, and Service metadata. | ||
|
|
||
| extra_labels (dict[str, Any]): ExtraLabels are applied to the Deployment metadata, PodTemplate | ||
| metadata, and Service metadata. The operator-managed keys "app" | ||
| and "mcp-server" cannot be overridden. | ||
|
|
||
| mcp (dict[str, Any]): MCP defines Model Context Protocol specific properties of the server. | ||
| This section describes the MCP server's protocol-level behavior, | ||
| as opposed to how it is sourced, configured, or managed at | ||
| runtime. | ||
|
|
||
| runtime (dict[str, Any]): Runtime defines runtime management configuration. If not specified, | ||
| default runtime settings will be applied. | ||
|
|
||
| source (dict[str, Any]): Source is a required field that defines where the MCP server should be | ||
| sourced from. Currently supports container images, with potential | ||
| for additional source types in the future. This configuration | ||
| determines how the MCP server will be deployed and run. | ||
|
|
||
| """ | ||
| super().__init__(**kwargs) | ||
|
|
||
| self.config = config | ||
| self.extra_annotations = extra_annotations | ||
| self.extra_labels = extra_labels | ||
| self.mcp = mcp | ||
| self.runtime = runtime | ||
| self.source = source | ||
|
|
||
| def to_dict(self) -> None: | ||
|
|
||
| super().to_dict() | ||
|
|
||
| if not self.kind_dict and not self.yaml_file: | ||
| if self.config is None: | ||
| raise MissingRequiredArgumentError(argument="self.config") | ||
|
|
||
| if self.source is None: | ||
| raise MissingRequiredArgumentError(argument="self.source") | ||
|
Comment on lines
+92
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. to_dict() performs validation MCPServer.to_dict() raises MissingRequiredArgumentError when config or source is unset, which is validation logic inside a serializer. This violates the requirement that to_dict() only serialize fields without enforcing resource validity. Agent Prompt
|
||
|
|
||
| self.res["spec"] = {} | ||
| _spec = self.res["spec"] | ||
|
|
||
| _spec["config"] = self.config | ||
| _spec["source"] = self.source | ||
|
|
||
| if self.extra_annotations is not None: | ||
| _spec["extraAnnotations"] = self.extra_annotations | ||
|
|
||
| if self.extra_labels is not None: | ||
| _spec["extraLabels"] = self.extra_labels | ||
|
|
||
| if self.mcp is not None: | ||
| _spec["mcp"] = self.mcp | ||
|
|
||
| if self.runtime is not None: | ||
| _spec["runtime"] = self.runtime | ||
|
|
||
| # End of generated code | ||
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
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.
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.
2. Missing generated start marker
📘 Rule violation⚙ MaintainabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools