Add MCP entry password tool
ci / lint-test (pull_request) Successful in 1m46s
ci / build (pull_request) Successful in 2m40s

This commit is contained in:
Joe Julian
2026-05-14 09:06:59 -07:00
parent d9a4bc6b14
commit 13eeb3fe4a
2 changed files with 126 additions and 1 deletions
+46 -1
View File
@@ -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()