Skip to main content
Glama

Nx MCP Server

Official
by nrwl
docs-prompt.ts1.61 kB
import { httpRequest } from '@nx-console/shared-utils'; export type ChatTurn = { role: 'user' | 'assistant'; content: string; }; export type DocsPageSection = { heading: string; longer_heading: string; content: string; similarity: number; }; export async function getDocsContext( userQuery: string, lastAssistantMessage?: string, ): Promise<DocsPageSection[]> { const messages: ChatTurn[] = []; if (lastAssistantMessage) { messages.push({ role: 'assistant', content: lastAssistantMessage, }); } messages.push({ role: 'user', content: userQuery, }); const req = await httpRequest({ url: 'https://nx.dev/api/query-ai-embeddings', type: 'POST', headers: { 'Content-Type': 'application/json' }, data: JSON.stringify({ messages, }), }); const response = JSON.parse(req.responseText); return response.context.pageSections; } export function getDocsPrompt(docsPages: DocsPageSection[]): string { const pages = docsPages.slice(0, 4); if (pages.length === 0) { return ''; } const pagesText = pages .map( (page, index) => `- ${page.longer_heading ?? page.heading ?? index} <br/> ${page.content}`, ) .join('<br/>'); return `Below are some documentation sections that could be relevant to the user request. Read through them carefully. You don't have to use them to answer the user query, but they might help. Do not assume knowledge about nx, its configuration and options. Instead, base your replies on the provided metadata and these documentation sections. <br /><br />${pagesText}`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nrwl/nx-console'

If you have feedback or need assistance with the MCP directory API, please join our Discord server