Add MCP entry password tool
This commit is contained in:
@@ -24,7 +24,7 @@ func TestServerRegistersKeePassGOTools(t *testing.T) {
|
||||
for _, tool := range result.Tools {
|
||||
got = append(got, tool.Name)
|
||||
}
|
||||
want := []string{"find_browser_logins", "get_browser_credential", "get_session_status", "search_entries"}
|
||||
want := []string{"find_browser_logins", "get_browser_credential", "get_entry_password", "get_session_status", "search_entries"}
|
||||
if diff := cmp.Diff(want, got); diff != "" {
|
||||
t.Errorf("ListTools() names mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
@@ -124,6 +124,51 @@ func TestGetBrowserCredentialReturnsCredential(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEntryPasswordReturnsPasswordForUniqueMetadataMatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := &fakeVaultClient{
|
||||
entries: []*keepassgov1.Entry{
|
||||
{
|
||||
Id: "wrong-crew",
|
||||
Title: "Home Assistant",
|
||||
Username: "rusty",
|
||||
Password: "wrong-token",
|
||||
Url: "https://lights.example.invalid",
|
||||
Path: []string{"Root", "Shared"},
|
||||
},
|
||||
{
|
||||
Id: "codex-token",
|
||||
Title: "Home Assistant",
|
||||
Username: "codex",
|
||||
Password: "right-token",
|
||||
Url: "https://lights.example.invalid",
|
||||
Path: []string{"Root", "Codex"},
|
||||
},
|
||||
},
|
||||
}
|
||||
session, cleanup := newTestSession(t, client)
|
||||
defer cleanup()
|
||||
|
||||
result, err := session.CallTool(context.Background(), &mcp.CallToolParams{
|
||||
Name: "get_entry_password",
|
||||
Arguments: map[string]any{
|
||||
"path": []string{"Root", "Codex"},
|
||||
"query": "Home Assistant",
|
||||
"title": "home assistant",
|
||||
"username": "codex",
|
||||
"url": "https://lights.example.invalid",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CallTool(get_entry_password) error = %v", err)
|
||||
}
|
||||
got := result.StructuredContent.(map[string]any)
|
||||
if got["password"] != "right-token" {
|
||||
t.Errorf("CallTool(get_entry_password).password = %v, want %q", got["password"], "right-token")
|
||||
}
|
||||
}
|
||||
|
||||
func newTestSession(t *testing.T, vaultClient *fakeVaultClient) (*mcp.ClientSession, func()) {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user