fix: adding pagnation
This commit is contained in:
parent
207486ecca
commit
ea4779c2b3
|
|
@ -9,9 +9,9 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
"list_conclusions",
|
||||
{
|
||||
description: [
|
||||
"List conclusions (facts and observations) that Honcho has derived about a peer.",
|
||||
"List conclusions (facts and observations) that Honcho has derived about a peer (paginated).",
|
||||
"Use this to see what Honcho has learned. If no target is given, returns self-conclusions.",
|
||||
"Returns an array of conclusion objects with id, content, observer/observed IDs, and timestamps.",
|
||||
"Returns conclusion objects with pagination metadata.",
|
||||
].join("\n"),
|
||||
inputSchema: {
|
||||
peer_id: z.string().describe("The observer peer."),
|
||||
|
|
@ -30,18 +30,19 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
? peer.conclusionsOf(target_peer_id)
|
||||
: peer.conclusions;
|
||||
const page = await scope.list();
|
||||
const conclusions: Record<string, unknown>[] = [];
|
||||
for await (const c of page) {
|
||||
conclusions.push({
|
||||
return textResult({
|
||||
conclusions: page.items.map((c) => ({
|
||||
id: c.id,
|
||||
content: c.content,
|
||||
observer_id: c.observerId,
|
||||
observed_id: c.observedId,
|
||||
session_id: c.sessionId,
|
||||
created_at: c.createdAt,
|
||||
});
|
||||
}
|
||||
return textResult(conclusions);
|
||||
})),
|
||||
total: page.total,
|
||||
page: page.page,
|
||||
pages: page.pages,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
`Failed to list conclusions: ${e instanceof Error ? e.message : String(e)}`,
|
||||
|
|
|
|||
|
|
@ -42,20 +42,21 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
"list_peers",
|
||||
{
|
||||
description: [
|
||||
"List all peers in the current workspace.",
|
||||
"List peers in the current workspace (paginated).",
|
||||
"Use this to discover which users and agents exist.",
|
||||
"Returns an array of peer IDs.",
|
||||
"Returns peer IDs with pagination metadata.",
|
||||
].join("\n"),
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
const page = await ctx.honcho.peers();
|
||||
const peers: { id: string }[] = [];
|
||||
for await (const peer of page) {
|
||||
peers.push({ id: peer.id });
|
||||
}
|
||||
return textResult(peers);
|
||||
return textResult({
|
||||
peers: page.items.map((p) => ({ id: p.id })),
|
||||
total: page.total,
|
||||
page: page.page,
|
||||
pages: page.pages,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
`Failed to list peers: ${e instanceof Error ? e.message : String(e)}`,
|
||||
|
|
|
|||
|
|
@ -41,20 +41,21 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
"list_sessions",
|
||||
{
|
||||
description: [
|
||||
"List all sessions in the current workspace.",
|
||||
"List sessions in the current workspace (paginated).",
|
||||
"Use this to discover existing conversations.",
|
||||
"Returns an array of session IDs.",
|
||||
"Returns session IDs with pagination metadata.",
|
||||
].join("\n"),
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
const page = await ctx.honcho.sessions();
|
||||
const sessions: { id: string }[] = [];
|
||||
for await (const session of page) {
|
||||
sessions.push({ id: session.id });
|
||||
}
|
||||
return textResult(sessions);
|
||||
return textResult({
|
||||
sessions: page.items.map((s) => ({ id: s.id })),
|
||||
total: page.total,
|
||||
page: page.page,
|
||||
pages: page.pages,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
`Failed to list sessions: ${e instanceof Error ? e.message : String(e)}`,
|
||||
|
|
@ -320,9 +321,9 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
"get_session_messages",
|
||||
{
|
||||
description: [
|
||||
"Get all messages from a session, with optional metadata filtering.",
|
||||
"Get messages from a session (paginated), with optional metadata filtering.",
|
||||
"Use this to read the conversation history.",
|
||||
"Returns a paginated array of messages.",
|
||||
"Returns the first page of messages with pagination metadata.",
|
||||
].join("\n"),
|
||||
inputSchema: {
|
||||
session_id: z.string().describe("The session to get messages from."),
|
||||
|
|
@ -336,11 +337,12 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
try {
|
||||
const session = await ctx.honcho.session(session_id);
|
||||
const page = await session.messages(filters);
|
||||
const messages = [];
|
||||
for await (const msg of page) {
|
||||
messages.push(msg);
|
||||
}
|
||||
return textResult(formatMessages(messages));
|
||||
return textResult({
|
||||
messages: formatMessages(page.items),
|
||||
total: page.total,
|
||||
page: page.page,
|
||||
pages: page.pages,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
`Failed to get messages: ${e instanceof Error ? e.message : String(e)}`,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
description: [
|
||||
"Inspect the current workspace at a glance.",
|
||||
"Aggregates workspace metadata, configuration, peer IDs, and session IDs.",
|
||||
"Returns a single JSON object.",
|
||||
"Returns the first page of peers/sessions with total counts.",
|
||||
].join("\n"),
|
||||
inputSchema: {},
|
||||
},
|
||||
|
|
@ -24,22 +24,14 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
ctx.honcho.sessions(),
|
||||
]);
|
||||
|
||||
const peers: { id: string }[] = [];
|
||||
for await (const peer of peerPage) {
|
||||
peers.push({ id: peer.id });
|
||||
}
|
||||
|
||||
const sessions: { id: string }[] = [];
|
||||
for await (const session of sessionPage) {
|
||||
sessions.push({ id: session.id });
|
||||
}
|
||||
|
||||
return textResult({
|
||||
workspace_id: ctx.honcho.workspaceId,
|
||||
metadata,
|
||||
configuration,
|
||||
peers,
|
||||
sessions,
|
||||
peer_count: peerPage.total,
|
||||
peers: peerPage.items.map((p) => ({ id: p.id })),
|
||||
session_count: sessionPage.total,
|
||||
sessions: sessionPage.items.map((s) => ({ id: s.id })),
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
|
|
@ -54,20 +46,21 @@ export function register(server: McpServer, ctx: ToolContext) {
|
|||
"list_workspaces",
|
||||
{
|
||||
description: [
|
||||
"List all workspaces accessible to the current credentials.",
|
||||
"List workspaces accessible to the current credentials (paginated).",
|
||||
"Use this to discover available workspaces before selecting or switching context.",
|
||||
"Returns an array of workspace IDs.",
|
||||
"Returns workspace IDs with pagination metadata.",
|
||||
].join("\n"),
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
const page = await ctx.honcho.workspaces();
|
||||
const workspaces: { id: string }[] = [];
|
||||
for await (const workspace of page) {
|
||||
workspaces.push({ id: workspace });
|
||||
}
|
||||
return textResult(workspaces);
|
||||
return textResult({
|
||||
workspaces: page.items.map((id) => ({ id })),
|
||||
total: page.total,
|
||||
page: page.page,
|
||||
pages: page.pages,
|
||||
});
|
||||
} catch (e) {
|
||||
return errorResult(
|
||||
`Failed to list workspaces: ${e instanceof Error ? e.message : String(e)}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue