-
Notifications
You must be signed in to change notification settings - Fork 93
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
38
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.
+254
−9
Open
Changes from all commits
Commits
Show all changes
38 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 2bd0e2d
aider.org-init
rajp152k b048caf
code overview updates
rajp152k 94c91b3
code overview updates
rajp152k 089b94f
code overview updates
rajp152k d9e960c
pre phase 1 consolidation
rajp152k 6fb4515
tdd scratch pad init
rajp152k 834d5c8
tdd scope
rajp152k f985b09
karpor license init
rajp152k f0111e1
temporary err suppression
rajp152k 31d317f
iteration scratch cache thoughts
rajp152k 460a625
phase-1 init
rajp152k 07d6c81
mcp-go overview
rajp152k f388e97
phase 1 mcp-go understanding init
rajp152k 5e075a1
MCPStorageServer handles multiple storage backends
rajp152k fb97972
MCPStorageServerConstructure Update
rajp152k b39e5ff
comment updates
rajp152k 99136b2
todo for multiple storage backends
rajp152k a48a348
fix[type]: pkg/mcp/server.go storageEndpoints
rajp152k 40127dc
human thought updates
rajp152k e0f289d
TODO updates
rajp152k 59a1d1d
[skip ci] plan and todos updated
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,89 @@ | ||
// 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" | ||
_ "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 | ||
// TODO update mcpOptions to use the generic storage interface | ||
// should be able handle accept multiple storage backends | ||
// ElasticSearchAddresses []string | ||
} | ||
|
||
func NewMCPOptions() *mcpOptions { | ||
return &mcpOptions{} | ||
} | ||
|
||
func (o *mcpOptions) AddFlags(fs *pflag.FlagSet) { | ||
// TODO chart out how to handle multiple generic storage backends | ||
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 | ||
} | ||
|
||
// TODO update mcpOptions to use the generic storage interface | ||
//nolint:unparam | ||
func mcpRun(_ context.Context, options *mcpOptions) error { | ||
ctrl.SetLogger(klog.NewKlogr()) | ||
log := ctrl.Log.WithName("mcp") | ||
|
||
//TODO update so that this receives generic storage backends (more than 1) | ||
log.Info("Starting MCP SSE server", | ||
"port", options.SSEPort, ) | ||
|
||
|
||
//TODO update to use the generic storage interface for initialization | ||
//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 pickup syncer operations patterns for running the mcp server from app/syncer.go | ||
|
||
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,18 @@ | ||
// 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,18 @@ | ||
// 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,55 @@ | ||
// 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 new MCPStorageServer configuration | ||
func NewMCPStorageServer(storageEndpoints []storage.Storage, sseBaseURL string, sseAddr string) MCPStorageServer { | ||
mcpServer := server.NewMCPServer("MCP Storage Server", "0.0.1") | ||
sseServer := server.NewSSEServer(mcpServer, sseBaseURL) | ||
return MCPStorageServer{ | ||
Storages: storageEndpoints, | ||
MCPServer: mcpServer, | ||
sseServerBaseURL: sseBaseURL, | ||
sseServerBaseURLAddr: sseAddr, | ||
sseServer: sseServer, | ||
} | ||
} | ||
|
||
|
||
// TODO Modular design : storage backends should be pluggable | ||
// design MCPStorage interface that should be satisfied by the tools | ||
// all resource, tool, prompt handlers should use this MCPStorage interface | ||
// Read-only access to the storage backends needs to be configured | ||
// the server need not | ||
|
||
// for exposing a storage backend (DB queries): will be registering them as resources | ||
// https://github.com/mark3labs/mcp-go/blob/main/README.md#resources | ||
|
||
// Tools are supposed to have side effects and are not needed as of now in our case | ||
// Prompts can be integrated later on, when patterns emerge | ||
|
||
// Serve starts an SSE server on the baseaddr provided | ||
// TODO integrate this Serve into the main cmd | ||
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 { | ||
Storages []storage.Storage | ||
MCPServer *server.MCPServer //config for the mcp server | ||
sseServerBaseURL string | ||
sseServerBaseURLAddr string | ||
sseServer *server.SSEServer //SSE Server config | ||
} | ||
|
||
// Type Alias to tag MCPServer Tools | ||
type MCPToolName string | ||
|
||
// Type Alias to tag MCPServer Resources | ||
type MCPResourceName string | ||
|
||
// Type Alias to tag MCPServer Prompts | ||
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?