Skip to content
Open
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
60 changes: 60 additions & 0 deletions apps/web/src/lib/server/mcp/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,66 @@ describe('MCP HTTP Handler', () => {
expect(text.comments).toEqual([])
})

it('should exclude private comments from OAuth portal user post details', async () => {
const { getDeveloperConfig } = await import('@/lib/server/domains/settings/settings.service')
const { getCommentsWithReplies } = await import('@/lib/server/domains/posts/post.query')
vi.mocked(getDeveloperConfig)
.mockResolvedValueOnce({
mcpEnabled: true,
mcpPortalAccessEnabled: true,
})
.mockResolvedValueOnce({
mcpEnabled: true,
mcpPortalAccessEnabled: true,
})
Comment on lines +910 to +918
await setupValidOAuth({ role: 'user', scopes: ['read:feedback'] })

const { handleMcpRequest } = await import('../handler')
await handleMcpRequest(
oauthRequest(
jsonRpcRequest('initialize', {
protocolVersion: '2025-03-26',
capabilities: {},
clientInfo: { name: 'test', version: '1.0' },
})
)
)
await setupValidOAuth({ role: 'user', scopes: ['read:feedback'] })

const response = await handleMcpRequest(
oauthRequest(
jsonRpcRequest('tools/call', {
name: 'get_details',
arguments: { id: 'post_test' },
})
)
)

expect(response.status).toBe(200)
expect(vi.mocked(getCommentsWithReplies)).toHaveBeenCalledWith('post_test', undefined, {
includePrivate: false,
})
Comment on lines +942 to +945
})

it('should include private comments in team member post details', async () => {
const { getCommentsWithReplies } = await import('@/lib/server/domains/posts/post.query')
const handleMcpRequest = await initializeSession()

const response = await handleMcpRequest(
mcpRequest(
jsonRpcRequest('tools/call', {
name: 'get_details',
arguments: { id: 'post_test' },
})
)
)

expect(response.status).toBe(200)
expect(vi.mocked(getCommentsWithReplies)).toHaveBeenCalledWith('post_test', undefined, {
includePrivate: true,
})
Comment on lines +961 to +964
})

// ── get_details tool (changelog) ────────────────────────────────────────

it('should handle tools/call for get_details with changelog TypeID', async () => {
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/lib/server/mcp/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2043,14 +2043,14 @@ async function searchArticles(args: SearchArgs): Promise<CallToolResult> {
// ============================================================================

async function getPostDetails(postId: PostId, auth: McpAuthContext): Promise<CallToolResult> {
const includeTeamOnlyFields = isTeamMember(auth.role)

const [post, comments, mergedPosts] = await Promise.all([
getPostWithDetails(postId),
getCommentsWithReplies(postId),
getCommentsWithReplies(postId, undefined, { includePrivate: includeTeamOnlyFields }),
getMergedPosts(postId),
])

const includeTeamOnlyFields = isTeamMember(auth.role)

return jsonResult({
id: post.id,
title: post.title,
Expand Down
Loading