-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MCP access part 11: tsh auto reconnect #55942
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c93961
MCP access part 11: resumable connection
greedy52 783b455
revert app definition
greedy52 2a59b75
address pr comments
greedy52 e0a6b78
special error message for server info changed
greedy52 6d2998f
Merge branch 'master' of github.com:gravitational/teleport into STeve…
greedy52 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2025 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package mcp | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "syscall" | ||
|
|
||
| "github.com/gravitational/trace" | ||
| "github.com/mark3labs/mcp-go/mcp" | ||
| ) | ||
|
|
||
| const ( | ||
| // ReloginRequiredErrorMessage is the message returned to the MCP client | ||
| // when the tsh session expired. | ||
| ReloginRequiredErrorMessage = `It looks like your Teleport session expired, | ||
| you must relogin (using "tsh login" on a terminal) before continue using this | ||
| tool. After that, there is no need to update or relaunch the MCP client - just | ||
| try using it again.` | ||
| ) | ||
|
|
||
| // IsLikelyTemporaryNetworkError returns true if the error is likely a temporary | ||
| // network error. | ||
| func IsLikelyTemporaryNetworkError(err error) bool { | ||
| if trace.IsConnectionProblem(err) || | ||
| isTemporarySyscallNetError(err) { | ||
| return true | ||
| } | ||
|
|
||
| var dnsErr *net.DNSError | ||
| if errors.As(err, &dnsErr) { | ||
| return dnsErr.Temporary() | ||
| } | ||
|
|
||
| var netErr net.Error | ||
| if errors.As(err, &netErr) { | ||
| return netErr.Timeout() | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| func isTemporarySyscallNetError(err error) bool { | ||
| return errors.Is(err, syscall.EHOSTUNREACH) || | ||
| errors.Is(err, syscall.ENETUNREACH) || | ||
| errors.Is(err, syscall.ETIMEDOUT) || | ||
| errors.Is(err, syscall.ECONNREFUSED) | ||
| } | ||
|
greedy52 marked this conversation as resolved.
|
||
|
|
||
| // IsServerInfoChangedError returns true if the error indicates the remote MCP | ||
| // server's info has changed from previous connections. Auto-reconnection | ||
| // reports this scenario as an error case to be on the safe side in case things | ||
| // like tools have changed. | ||
| func IsServerInfoChangedError(err error) bool { | ||
| var serverInfoChangedError *serverInfoChangedError | ||
| return errors.As(err, &serverInfoChangedError) | ||
| } | ||
|
|
||
| type serverInfoChangedError struct { | ||
| expectedInfo mcp.Implementation | ||
| currentInfo mcp.Implementation | ||
| } | ||
|
|
||
| func (e *serverInfoChangedError) Error() string { | ||
| return fmt.Sprintf("server info has changed, expected %v, got %v", e.expectedInfo, e.currentInfo) | ||
| } | ||
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 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2025 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package mcp | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/mark3labs/mcp-go/mcp" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIsServerInfoChangedError(t *testing.T) { | ||
| err := &serverInfoChangedError{ | ||
| expectedInfo: mcp.Implementation{ | ||
| Name: "i-am-mcp", | ||
| Version: "1.0.0", | ||
| }, | ||
| currentInfo: mcp.Implementation{ | ||
| Name: "i-am-mcp", | ||
| Version: "1.1.0", | ||
| }, | ||
| } | ||
| require.True(t, IsServerInfoChangedError(err)) | ||
| } |
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.