-
Notifications
You must be signed in to change notification settings - Fork 92
WIP feat:MCP Support init #798
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
rajp152k
wants to merge
17
commits into
KusionStack:main
Choose a base branch
from
rajp152k:mcp-support
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
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7467e36
feat(MCP): mcp SSE init (elasticsearch storage)
rajp152k 0b0764d
chore(fmt): gofumpted mcp.go
rajp152k cd14298
chore(logging): ctrl, klog setup for uniformity
rajp152k 7285ace
chore(esclient): mcp elasticsearch client setup
rajp152k 557456c
chore(format): make format
rajp152k 2e440c3
fix(cilint): unused contexts and vars fix
rajp152k 320e8b5
fix(lint): golangci-lint govet fix
rajp152k d5b5b7a
fix(err): error return for esclient failure
rajp152k 0d52bb5
feat(pkg/mcp): structure init for pkg/mcp
rajp152k 1831e4e
chore(mod): go mod tidy post get mcp-golang
rajp152k 481ea31
feat(mcp): MCPServer type init
rajp152k 4003a96
fix(mcp-go): mcp-golang -> mcp-go
rajp152k 11433b7
feat(mcptypes): basic MCP entity type aliases
rajp152k 972d247
feat(mcp): MCPStorageServer struct,New, Serve init
rajp152k f042255
feat(mcp): prompts,tools,resources init
rajp152k 900ffda
Merge remote-tracking branch 'origin/main' into mcp-support
rajp152k 5294e1c
[skip ci] tdd base
rajp152k 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright The Karpor 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 app | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/KusionStack/karpor/pkg/infra/search/storage/elasticsearch" | ||
"github.com/KusionStack/karpor/pkg/mcp" | ||
esclient "github.com/elastic/go-elasticsearch/v8" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
type mcpOptions struct { | ||
SSEPort string | ||
ElasticSearchAddresses []string | ||
} | ||
|
||
func NewMCPOptions() *mcpOptions { | ||
return &mcpOptions{} | ||
} | ||
|
||
func (o *mcpOptions) AddFlags(fs *pflag.FlagSet) { | ||
fs.StringVar(&o.SSEPort, "MCP SSE server exposure port", ":7999", "The address expossing the mcp server") | ||
fs.StringSliceVar(&o.ElasticSearchAddresses, "elastic-search-addresses", nil, "The elastic search address") | ||
} | ||
|
||
func NewMCPCommand(ctx context.Context) *cobra.Command { | ||
options := NewMCPOptions() | ||
cmd := &cobra.Command{ | ||
Use: "mcp", | ||
Short: "start a storage mcp server to enable natural language interaction capabilities with the storage backend", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return mcpRun(ctx, options) | ||
}, | ||
} | ||
options.AddFlags(cmd.Flags()) | ||
return cmd | ||
} | ||
|
||
//nolint:unparam | ||
func mcpRun(ctx context.Context, options *mcpOptions) error { | ||
ctrl.SetLogger(klog.NewKlogr()) | ||
log := ctrl.Log.WithName("mcp") | ||
|
||
log.Info("Starting MCP SSE server", | ||
"port", options.SSEPort, | ||
"esAddresses", options.ElasticSearchAddresses) | ||
|
||
//nolint:contextcheck | ||
es, err := elasticsearch.NewStorage(esclient.Config{ | ||
Addresses: options.ElasticSearchAddresses, | ||
}) | ||
if err != nil { | ||
log.Error(err, "unable to init elasticsearch client") | ||
return err | ||
} | ||
log.Info("Acquired elasticsearch storage backend", "esStorage", es) | ||
|
||
// TODO : integrate mcp-golang SSE server | ||
|
||
log.Info("TODO: yet to implement mcp functionality") | ||
log.Info("see /cmd/karpor/app/mcp.go for further directives") | ||
return 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
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,4 @@ | ||
package mcp | ||
|
||
import ( | ||
) |
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,4 @@ | ||
package mcp | ||
|
||
import ( | ||
) |
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,41 @@ | ||
// Copyright The Karpor 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 mcp | ||
|
||
import ( | ||
"github.com/KusionStack/karpor/pkg/infra/search/storage" | ||
_ "github.com/KusionStack/karpor/pkg/infra/search/storage/elasticsearch" | ||
_ "github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
_ "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
// NewMCPStorageServer yields a storage initialized MCPServer struct | ||
func NewMCPStorageServer(storageEndpoint storage.Storage, sseBaseURL string, sseAddr string) MCPStorageServer { | ||
mcpServer := server.NewMCPServer("MCP Storage Server", "0.0.1") | ||
sseServer := server.NewSSEServer(mcpServer, sseBaseURL) | ||
return MCPStorageServer{ | ||
Storage: storageEndpoint, | ||
MCPServer: mcpServer, | ||
sseServerBaseURL: sseBaseURL, | ||
sseServerBaseURLAddr: sseAddr, | ||
sseServer: sseServer, | ||
} | ||
} | ||
|
||
// Serve starts an SSE server on the baseaddr provided | ||
func (m *MCPStorageServer) Serve() error { | ||
return m.sseServer.Start(m.sseServerBaseURLAddr) | ||
} |
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,17 @@ | ||
// Copyright The Karpor 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 mcp | ||
|
||
import ( | ||
) |
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,40 @@ | ||
// Copyright The Karpor 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 mcp | ||
|
||
import ( | ||
"github.com/KusionStack/karpor/pkg/infra/search/storage" | ||
_ "github.com/KusionStack/karpor/pkg/infra/search/storage/elasticsearch" | ||
_ "github.com/mark3labs/mcp-go/mcp" | ||
"github.com/mark3labs/mcp-go/server" | ||
) | ||
|
||
// MCPServer is the main object that holds the necessary fields and components for the mcp server component to expose the storage backend via resources, tools and prompts | ||
type MCPStorageServer struct { | ||
Storage storage.Storage //the storage backend to be exposed by the MCPStorageServer | ||
MCPServer *server.MCPServer //manages configurations of tools, resources, prompts and their handlers | ||
sseServerBaseURL string //baseURL on which the sse server is exposed | ||
sseServerBaseURLAddr string //port on which the sse server is exposed | ||
sseServer *server.SSEServer //manages configuration of the HTTP based SSE server on which the MCPServer is exposed | ||
} | ||
|
||
// MCPToolName is a string tag for an mcp server tool | ||
type MCPToolName string | ||
|
||
// MCPResourceName is a string tag for an mcp server resource | ||
type MCPResourceName string | ||
|
||
// MCPPromptName is a string tag for an mcp server prompt | ||
type MCPPromptName string |
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.
Is this line necessary?