Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/mcp/src/server/mcp/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,35 @@ describe("mcp tool server", () => {
expect(getMessages).not.toHaveBeenCalled()
})

it.each([
{ tool: "conversations.create", scope: "messages:write", arguments: { title: "Roadmap", spaceId: "9223372036854775808" }, field: "spaceId" },
{ tool: "conversations.list", scope: "messages:read", arguments: { afterChatId: "9223372036854775808" }, field: "afterChatId" },
{ tool: "messages.list", scope: "messages:read", arguments: { chatId: "7", offsetId: "9223372036854775808" }, field: "offsetId" },
{ tool: "messages.send", scope: "messages:write", arguments: { chatId: "7", text: "hi", replyToMsgId: "9223372036854775808" }, field: "replyToMsgId" },
].flatMap((testCase) => (["legacy", "submission-v2"] as const).map((contractVersion) => ({ ...testCase, contractVersion }))))(
"$tool names $field in its invalid ID error ($contractVersion)",
async ({ tool, scope, arguments: args, field, contractVersion }) => {
const createChat = vi.fn<InlineApi["createChat"]>()
const listChats = vi.fn<NonNullable<InlineApi["listChats"]>>()
const recentMessages = vi.fn<InlineApi["recentMessages"]>()
const sendMessage = vi.fn<InlineApi["sendMessage"]>()
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {})
try {
const server = createInlineMcpServer({ grant, inline: createInlineStub({ createChat, listChats, recentMessages, sendMessage }), contractVersion })
const authInfo = createAuthInfo([scope])
const { transport, sent } = await connectAndInitialize(server, authInfo)
await sendRequest(transport, { jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: tool, arguments: args } } as any, { authInfo })
const response = await waitForResponse(sent, 2)
expect(response.result.isError).toBe(true)
expect(response.result.content[0].text).toContain(`invalid ${field}`)
expect(response.result.content[0].text).not.toContain("invalid chatId")
for (const fn of [createChat, listChats, recentMessages, sendMessage]) expect(fn).not.toHaveBeenCalled()
} finally {
infoSpy.mockRestore()
}
},
)

it.each([
{ since: "2026-02-31", until: undefined, error: "calendar date does not exist" },
{ since: "2026-02-31T00:00:00Z", until: undefined, error: "calendar date does not exist" },
Expand Down
8 changes: 4 additions & 4 deletions packages/mcp/src/server/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ export function createInlineMcpServer(params: {
const onlyUnread = unreadOnly === true
const completeCatalog = includeSubthreads === true
const safeSort = parseConversationSort(sort ?? (completeCatalog || afterChatId ? "id" : undefined), !!safeQuery)
const parsedAfterChatId = afterChatId ? parseChatId(afterChatId) : undefined
const parsedAfterChatId = afterChatId ? parseInlineId(afterChatId, "afterChatId") : undefined
if ((completeCatalog || parsedAfterChatId != null || safeSort === "id") && (safeQuery || safeSort !== "id")) {
throw new Error("archive discovery and afterChatId require id sort and no query")
}
Expand Down Expand Up @@ -2418,7 +2418,7 @@ export function createInlineMcpServer(params: {

const created = await params.inline.createChat({
title: args.title,
...(args.spaceId ? { spaceId: parseChatId(args.spaceId) } : {}),
...(args.spaceId ? { spaceId: parseInlineId(args.spaceId, "spaceId") } : {}),
...(args.description ? { description: args.description } : {}),
...(args.emoji ? { emoji: args.emoji } : {}),
...(args.isPublic != null ? { isPublic: args.isPublic } : {}),
Expand Down Expand Up @@ -3122,7 +3122,7 @@ export function createInlineMcpServer(params: {
const target = submissionV2
? { chatId: parseChatId(chatId!) }
: parseTarget({ chatId, userId }, "messages.list")
const parsedOffsetId = offsetId ? parseChatId(offsetId) : undefined
const parsedOffsetId = offsetId ? parseInlineId(offsetId, "offsetId") : undefined
const { parsedSince, parsedUntil } = parseTimeRange(since, until)
const safeContent = parseContentFilter(content)
const recent = await params.inline.recentMessages({
Expand Down Expand Up @@ -3486,7 +3486,7 @@ export function createInlineMcpServer(params: {
const res = await params.inline.sendMessage({
...target,
text,
...(replyToMsgId ? { replyToMsgId: parseChatId(replyToMsgId) } : {}),
...(replyToMsgId ? { replyToMsgId: parseInlineId(replyToMsgId, "replyToMsgId") } : {}),
sendMode: safeSendMode,
parseMarkdown: true,
...(sign === false ? { unsigned: true } : {}),
Expand Down
Loading