@djangocfg/widget-mcp

中文文档
0.4.31发布于 2026/11/05MITTypeScriptES Module零依赖近 30 天下载 7495

Connect an AI assistant to a django-cfg MCP server in one press, with the user's own key; plus the OAuth consent page. 17 locales.

原始使用文档
文档目录8 节
  1. Install
  2. Connect
  3. What the server offers
  4. In Settings
  5. Renew access
  6. Approving an assistant
  7. Exports
  8. Docs

@djangocfg/widget-mcp

Connect an AI assistant to a django-cfg MCP server in one press. The package also holds the OAuth consent page the server sends the visitor to.

  • Grouped by app. Home is one tile per app: Claude, ChatGPT, Codex, Gemini, Notion, Perplexity, Cursor, VS Code, LM Studio, Goose, and "Other app". Opening an app lists each documented way to connect it (Claude: web and desktop connector, and Claude Code).
  • Claude (web, desktop), ChatGPT, Notion, Perplexity and Goose connect by URL and sign in with OAuth.
  • Claude Code, Codex, Gemini CLI, Cursor, VS Code and LM Studio get the signed-in user's own API key in the command or deeplink.
  • Any other app (Mistral, Copilot Studio, n8n, Zapier, Make): an "Other app" screen with a stepper and a Copy button per field (URL, name, header name, key), and "Copy setup instructions for your AI".
  • One decision per screen: home is one tile per app; each tile opens that app's screen. initialView opens one directly; locale overrides the host's language.
  • Signed-out visitors see every option, but sign in before they connect.
  • 17 locales. The widget follows the active @djangocfg/i18n locale.

Source-shipped, no build step.

Install

pnpm add @djangocfg/widget-mcp

The host needs:

  • BaseApp with auth enabled, so useAuth works and the global AuthDialog is mounted;
  • the Tailwind @source over widgets/*/src/**, which every django-cfg host already has.

Connect

On a django-cfg host the key is the signed-in user's own django-cfg API key. No key code is needed:

import { McpConnect } from '@djangocfg/widget-mcp';

<McpConnect
  server={{ url: 'https://mcp.example.com/mcp/', alias: 'example', name: 'Example' }}
  copy={{ lede: 'Search the catalogue from your assistant.' }}
/>;

The widget reveals the key through @djangocfg/api (useApiKey, over the generated cfg/accounts/api-key hooks, on the host's configured client and auth). A host with its own key system (MLS and Carapis keep apps.api_keys) passes loadKey:

import type { McpKeyLoader } from '@djangocfg/widget-mcp';

const loadKey: McpKeyLoader = async ({ token, signal }) => {
  const response = await fetch(`${API_URL}/api/keys/`, {
    headers: { Authorization: `Bearer ${token ?? ''}` },
    signal,
  });
  if (!response.ok) throw new Error(String(response.status));
  const { results } = await response.json();
  return results.find((row) => row.is_valid)?.plain_key ?? null;
};

<McpConnect server={server} loadKey={loadKey} keysUrl="https://my.example.com/api-keys" />;
PropWhat
serverOptional. Every field defaults from the host: url is the API host + /cfg/mcp/, alias and name come from the host name. url is the MCP endpoint. alias is the key clients register it under. name is the connector name Claude shows.
loadKeyOptional. The host's own key system: returns the signed-in user's key, or null when the account has none. Called only for a signed-in user. Throwing shows Retry. Omit it and the key is the user's django-cfg API key.
keysUrlWhere a user creates a key. Shown when loadKey returns null.
createKeyMints a key and returns its secret once, for hosts that keep only a hash. Offered when loadKey finds none.
bareHide the built-in title, for a host that already shows one (the Settings section). The lede stays.
footerExtra host content under the panel and the renew section.
copyOverrides any subset of the bundled strings.

What the server offers

With a key ready, the panel fetches <server url>/info/ (header X-MCP-Access-Key) and lists the tools under "This connector can" (five rows, then "Show N more"). The same data lands in McpServer.info (instructions, tools, resources, prompts; parse with parseServerInfo), and then:

  • the "Copy prompt for an AI agent" text ends with the server instructions and the resource URIs;
  • the "Other client" JSON gets top-level instructions and resources beside mcpServers (the entry itself is unchanged).

Without info (older server, failed request, no key yet) nothing is shown and the output is exactly what it was. A server on its own host needs no special kind: pass server={{ url, alias, name }}; resolveMcpServer derives from the API host only for fields you omit.

In Settings

<SettingsDialog sections={[mcpSettingsSection()]} />

mcpSettingsSection() returns a section for the @djangocfg/layouts Settings dialog. It lands in the Platform group next to API keys, and the widget's own lede is its subtitle, in the host's language. server defaults to the API host + /cfg/mcp/; pass options only for another server. Only a backend running django-cfg MCP has something to connect to, so add it only there. Layouts does not depend on this widget: the host passes the section in.

Renew access

When the key is django-cfg's (no loadKey, no createKey), a signed-in user gets one button under the panel: Renew access. It says it disconnects every assistant and gives one new key, and asks to confirm. Confirming calls the generated useCfgAccountsApiKeyRegenerateCreate (through useApiKey().regenerate); the new key replaces the one in the panel's commands and snippets. "Last renewed " comes from reissued_at. The key is durable and revealable, so it is not "shown once". A host with its own keys does not get this section.

Approving an assistant

mcpSettingsSection() is also the OAuth approval screen. django-cfg's authorize sends the browser to <site_url>/#settings/mcp?request=…; the section posts the signed request to oauth/approve/ for the signed-in user, shows one status line above the connect list and follows redirect_to back to the assistant. Nothing is asked. A guest is sent to sign-in and returned to the same link (@djangocfg/layouts ≥ 2.1.598).

Exports

PathWhat
.McpConnect, useMcpCopy, MCP_DICTIONARIES, the assistant marks, the install builders
./installThe builders only, with no React: commands, deeplinks, mcpServersConfig, MCP_KEY_HEADER
./marksThe assistant marks only: ClaudeIcon, ClaudeColorIcon, OpenAIIcon, CodexIcon, CursorIcon, VSCodeIcon. Plain SVG, server-safe, for a host's own trigger.

Docs

  • @docs/ explains how it works.
  • Storybook: Widgets/Mcp/Connect (signed out, signed in, no key, key error, checking, django-cfg key, renew) and Widgets/Mcp/Consent (ready, sends-to, long client name, invalid link, checking).
  • The server side, and what each assistant does after Allow: connect-assistants.
  • CLAUDE.md lists what is easy to break.

版本与发布记录

@djangocfg/widget-mcp 共发布 33 个版本,首次发布于 2026/10/23;过去 12 个月发布了 33 个版本。

版本发布日期距今
0.4.31latest2026/11/057 天前
0.4.302026/11/057 天前
0.4.282026/11/057 天前
0.4.272026/11/047 天前
0.4.262026/11/047 天前
0.4.252026/11/047 天前

关于 @djangocfg/widget-mcp 的常见问题

@djangocfg/widget-mcp 是什么?

Connect an AI assistant to a django-cfg MCP server in one press, with the user's own key; plus the OAuth consent page. 17 locales.

如何安装 @djangocfg/widget-mcp?

在项目目录运行 npm install @djangocfg/widget-mcp,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=15.0.0)、react(^19.0.0)、react-dom(^19.0.0)、lucide-react(^1.68.0)、@djangocfg/api(^2.1.619)、@djangocfg/i18n(^2.1.619)、@djangocfg/ui-core(^2.1.619)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@djangocfg/widget-mcp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@djangocfg/widget-mcp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@djangocfg/widget-mcp 可以商用吗?

@djangocfg/widget-mcp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@djangocfg/widget-mcp 的下载量有多少?

根据 npm 官方下载统计,@djangocfg/widget-mcp 在 2026/10/13 – 2026/11/11 这 30 天内被下载 7,495 次,日均约 250 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@djangocfg/widget-mcp 还在维护吗?

最新版本 0.4.31 发布于 2026/11/05(7 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。