Skip to content

Commit fa8688c

Browse files
committed
Fix MCP nested response handling for repo_reader tool
1 parent c04f5f1 commit fa8688c

3 files changed

Lines changed: 44 additions & 20 deletions

File tree

client/src/lib/api.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,25 @@ async function mcp<T>(tool: string, input: Record<string, any> = {}): Promise<T>
3636
export const api = {
3737
// ✅ method syntax (preferred)
3838
async listRepos(): Promise<{ repos: string[] }> {
39-
const data = await mcp<{ repositories: { full_name: string; branches?: string[] }[] }>(
40-
"repo_reader",
41-
{}
42-
);
43-
const repos = (data.repositories ?? []).map(r => r.full_name);
39+
const outer = await mcp<{
40+
success: boolean;
41+
data: { provider: string; user: string; repositories: { full_name: string }[] };
42+
}>("repo_reader", {});
43+
44+
const inner = outer?.data;
45+
const repos = inner?.repositories?.map(r => r.full_name) ?? [];
4446
return { repos };
4547
},
4648

4749
async listBranches(repo: string): Promise<{ branches: string[] }> {
48-
const data = await mcp<{ repositories: { full_name: string; branches?: string[] }[] }>(
49-
"repo_reader",
50-
{}
51-
);
52-
const item = (data.repositories ?? []).find(r => r.full_name === repo);
53-
return { branches: item?.branches ?? [] };
50+
const outer = await mcp<{
51+
success: boolean;
52+
data: { provider: string; user: string; repositories: { full_name: string; branches?: string[] }[] };
53+
}>("repo_reader", {});
54+
55+
const inner = outer?.data;
56+
const match = inner?.repositories?.find(r => r.full_name === repo);
57+
return { branches: match?.branches ?? [] };
5458
},
5559

5660
async createPipeline(payload: any) {

client/src/pages/ConnectPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export default function ConnectPage() {
4848
<GlassButton
4949
variant="secondary"
5050
className="bg-white/20 hover:bg-white/30 text-white"
51-
onClick={loadRepos}
51+
onClick={() => {
52+
console.log("[Page] Re-sync clicked");
53+
loadRepos();
54+
}}
5255
>
5356
Re-sync Repos
5457
</GlassButton>
@@ -61,6 +64,7 @@ export default function ConnectPage() {
6164
<Select
6265
value={repo ?? ""}
6366
onValueChange={(v) => {
67+
console.log("[Page] Repo selected:", v);
6468
setRepo(v);
6569
loadBranches(v);
6670
}}

client/src/store/useRepoStore.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,22 @@ export const useRepoStore = create<RepoState & RepoActions>()(
4343
setBranch: (b) => set({ branch: b }),
4444

4545
async loadRepos() {
46+
console.log("[Store] loadRepos() start");
4647
set({ loading: true, error: undefined });
48+
4749
try {
48-
const { repos } = await api.listRepos(); // requires session cookie from OAuth
50+
const result = await api.listRepos();
51+
console.log("[Store] loadRepos() result:", result);
52+
4953
set({
50-
repos: repos ?? [],
51-
connected: true, // ← we’re authenticated
54+
repos: result?.repos ?? [],
55+
connected: true,
5256
loading: false,
5357
});
58+
59+
console.log("[Store] loadRepos() repos saved:", result?.repos);
5460
} catch (e: any) {
55-
// If unauthorized, backend should return 401 and this sets connected false.
61+
console.error("[Store] loadRepos() error:", e);
5662
set({
5763
error: e?.message ?? String(e),
5864
connected: false,
@@ -63,18 +69,28 @@ export const useRepoStore = create<RepoState & RepoActions>()(
6369
},
6470

6571
async loadBranches(repo: string) {
72+
console.log("[Store] loadBranches() start for repo:", repo);
6673
set({ loading: true, error: undefined, repo, branch: null, branches: [] });
74+
6775
try {
68-
const { branches } = await api.listBranches(repo);
69-
// Optional: preselect a sensible default branch
70-
const list = branches ?? [];
71-
const preferred = list.find(b => b === "main") ?? list.find(b => b === "master") ?? null;
76+
const result = await api.listBranches(repo);
77+
console.log("[Store] loadBranches() result:", result);
78+
79+
const list = result?.branches ?? [];
80+
const preferred =
81+
list.find(b => b === "main") ??
82+
list.find(b => b === "master") ??
83+
null;
84+
7285
set({
7386
branches: list,
7487
branch: preferred,
7588
loading: false,
7689
});
90+
91+
console.log("[Store] loadBranches() branches saved:", list);
7792
} catch (e: any) {
93+
console.error("[Store] loadBranches() error:", e);
7894
set({
7995
error: e?.message ?? String(e),
8096
loading: false,

0 commit comments

Comments
 (0)