fix: resolve resource names in get/describe (not just IDs)
fetchResource and fetchSingleResource now use resolveNameOrId so `mcpctl get server ha-mcp` works by name, not just by ID. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { createLoginCommand, createLogoutCommand } from './commands/auth.js';
|
|||||||
import { ApiClient } from './api-client.js';
|
import { ApiClient } from './api-client.js';
|
||||||
import { loadConfig } from './config/index.js';
|
import { loadConfig } from './config/index.js';
|
||||||
import { loadCredentials } from './auth/index.js';
|
import { loadCredentials } from './auth/index.js';
|
||||||
|
import { resolveNameOrId } from './commands/shared.js';
|
||||||
|
|
||||||
export function createProgram(): Command {
|
export function createProgram(): Command {
|
||||||
const program = new Command()
|
const program = new Command()
|
||||||
@@ -48,15 +49,27 @@ export function createProgram(): Command {
|
|||||||
|
|
||||||
const client = new ApiClient({ baseUrl, token: creds?.token ?? undefined });
|
const client = new ApiClient({ baseUrl, token: creds?.token ?? undefined });
|
||||||
|
|
||||||
const fetchResource = async (resource: string, id?: string): Promise<unknown[]> => {
|
const fetchResource = async (resource: string, nameOrId?: string): Promise<unknown[]> => {
|
||||||
if (id) {
|
if (nameOrId) {
|
||||||
|
let id: string;
|
||||||
|
try {
|
||||||
|
id = await resolveNameOrId(client, resource, nameOrId);
|
||||||
|
} catch {
|
||||||
|
id = nameOrId;
|
||||||
|
}
|
||||||
const item = await client.get(`/api/v1/${resource}/${id}`);
|
const item = await client.get(`/api/v1/${resource}/${id}`);
|
||||||
return [item];
|
return [item];
|
||||||
}
|
}
|
||||||
return client.get<unknown[]>(`/api/v1/${resource}`);
|
return client.get<unknown[]>(`/api/v1/${resource}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchSingleResource = async (resource: string, id: string): Promise<unknown> => {
|
const fetchSingleResource = async (resource: string, nameOrId: string): Promise<unknown> => {
|
||||||
|
let id: string;
|
||||||
|
try {
|
||||||
|
id = await resolveNameOrId(client, resource, nameOrId);
|
||||||
|
} catch {
|
||||||
|
id = nameOrId;
|
||||||
|
}
|
||||||
return client.get(`/api/v1/${resource}/${id}`);
|
return client.get(`/api/v1/${resource}/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user