Token导航 LogoToken导航TokenDH.com
开发操作浏览器github未标认证来源可访问许可证需确认审计通过

client-setup客户端设置

Agent Skill

client-setup 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

423

周安装

18

GitHub Stars

40,062

下载量

148
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:client-setup(客户端设置)
来源仓库:https://github.com/trpc/trpc
仓库路径:skills/client-setup
安装命令:
npx skills add https://github.com/trpc/trpc --skill client-setup
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/trpc/trpc --skill client-setup

简介

client-setup 演示 tRPC 客户端连接配置方法,包含类型安全调用与 HTTP 批处理链路设置。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中学习服务端通信架构与实践案例。
  • 提供从路由定义到客户端初始化的完整代码示例,便于理解类型推导机制。
  • 实际部署时应替换为真实服务端地址,并配置身份认证与安全策略。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

tRPC -- Client Setup

Setup

// server.ts
import { initTRPC } from '@trpc/server';
import { z } from 'zod';

const t = initTRPC.create();

const appRouter = t.router({
  user: t.router({
    byId: t.procedure
      .input(z.object({ id: z.string() }))
      .query(({ input }) => ({ id: input.id, name: 'Bilbo' })),
    create: t.procedure
      .input(z.object({ name: z.string() }))
      .mutation(({ input }) => ({ id: '1', ...input })),
  }),
});

export type AppRouter = typeof appRouter;
// client.ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

const client = createTRPCClient<AppRouter>({
  links: [
    httpBatchLink({
      url: 'http://localhost:3000/trpc',
    }),
  ],
});

const user = await client.user.byId.query({ id: '1' });
const created = await client.user.create.mutate({ name: 'Frodo' });

Core Patterns

Dynamic Auth Headers

import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

let token = '';

export function setToken(newToken: string) {
  token = newToken;
}

export const client = createTRPCClient<AppRouter>({
  links: [
    httpBatchLink({
      url: 'http://localhost:3000/trpc',
      headers() {
        return {
          Authorization: token ? `Bearer ${token}` : '',
        };
      },
    }),
  ],
});

The headers callback is invoked on every HTTP request, so token changes take effect immediately.

Inferring Procedure Input and Output Types

import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
import type { AppRouter } from './server';

type RouterInput = inferRouterInputs<AppRouter>;
type RouterOutput = inferRouterOutputs<AppRouter>;

type UserCreateInput = RouterInput['user']['create'];
type UserByIdOutput = RouterOutput['user']['byId'];

Aborting Requests with AbortController

import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

const client = createTRPCClient<AppRouter>({
  links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
});

const ac = new AbortController();
const query = client.user.byId.query({ id: '1' }, { signal: ac.signal });
ac.abort();

Typed Error Handling

import { TRPCClientError } from '@trpc/client';
import type { AppRouter } from './server';

function isTRPCClientError(
  cause: unknown,
): cause is TRPCClientError<AppRouter> {
  return cause instanceof TRPCClientError;
}

try {
  await client.user.byId.query({ id: '1' });
} catch (cause) {
  if (isTRPCClientError(cause)) {
    console.log('tRPC error code:', cause.data?.code);
  }
}

Common Mistakes

[CRITICAL] Missing AppRouter type parameter on createTRPCClient

Wrong:

const client = createTRPCClient({ links: [httpBatchLink({ url })] });

Correct:

import type { AppRouter } from './server';

const client = createTRPCClient<AppRouter>({ links: [httpBatchLink({ url })] });

Without the type parameter, all procedure calls return any and type safety is completely lost.

Source: www/docs/client/vanilla/setup.mdx

[CRITICAL] Transformer goes on individual links, not createTRPCClient

In v11, the transformer option is on individual terminating links, not the client constructor:

import superjson from 'superjson';

createTRPCClient<AppRouter>({
  links: [
    httpBatchLink({
      url: 'http://localhost:3000',
      transformer: superjson,
    }),
  ],
});

In v11, the transformer option was moved from the client constructor to individual terminating links. Passing it to createTRPCClient throws a TypeError.

Source: packages/client/src/internals/TRPCUntypedClient.ts

[CRITICAL] Transformer on server but not on client links

Wrong:

// Server: initTRPC.create({ transformer: superjson })
// Client:
httpBatchLink({ url: 'http://localhost:3000' });

Correct:

// Server: initTRPC.create({ transformer: superjson })
// Client:
httpBatchLink({ url: 'http://localhost:3000', transformer: superjson });

If the server uses a transformer, every terminating link on the client must also specify that transformer. Mismatch causes "Unable to transform response" errors.

Source: https://github.com/trpc/trpc/issues/7083

[CRITICAL] Using import instead of import type for AppRouter

Wrong:

import { AppRouter } from '../server/router';

Correct:

import type { AppRouter } from '../server/router';

A non-type import pulls the entire server bundle into the client. Use import type so it is erased at build time.

Source: www/docs/client/vanilla/setup.mdx

[CRITICAL] Importing appRouter value to derive type in client

Wrong:

import { appRouter } from '../server/router';

type AppRouter = typeof appRouter;

Correct:

// In server: export type AppRouter = typeof appRouter;
// In client:
import type { AppRouter } from '../server/router';

Importing the appRouter value (not just the type) bundles the entire server into the client, shipping server code to the browser.

Source: www/docs/server/routers.md

[CRITICAL] Using type assertions to bypass AppRouter import errors

Wrong:

const client = createTRPCClient<any>({ links: [httpBatchLink({ url })] });

Correct:

// Fix the import path or monorepo configuration
import type { AppRouter } from '@myorg/api-types';

const client = createTRPCClient<AppRouter>({ links: [httpBatchLink({ url })] });

Casting to any or manually recreating the router type destroys end-to-end type safety. Fix the import path or monorepo config instead.

Source: www/docs/client/vanilla/setup.mdx

[CRITICAL] Using createTRPCProxyClient (renamed in v11)

Wrong:

import { createTRPCProxyClient } from '@trpc/client';

Correct:

import { createTRPCClient } from '@trpc/client';

createTRPCProxyClient was renamed to createTRPCClient in v11.

Source: www/docs/client/vanilla/setup.mdx

[CRITICAL] Treating tRPC as a REST API

Wrong:

fetch('/api/trpc/users/123', { method: 'GET' });

Correct:

const user = await client.user.byId.query({ id: '123' });
// Raw equivalent: GET /api/trpc/user.byId?input={"id":"123"}

tRPC uses JSON-RPC over HTTP. Procedures are called by dot-separated name with JSON input, not by REST resource paths.

Source: www/docs/client/overview.md

[HIGH] HTML error page instead of JSON response

If you see couldn't parse JSON, invalid character '<', the tRPC endpoint returned an HTML page (404/503) instead of JSON. This means the url in your link config is wrong or infrastructure routing is misconfigured -- it is not a tRPC bug. Verify the URL matches your adapter's mount point.

Source: www/docs/client/vanilla/setup.mdx

See Also

  • links -- configure httpBatchLink, httpLink, splitLink, and other link types
  • superjson -- set up SuperJSON transformer on server and client
  • server-setup -- define routers, procedures, context, and export AppRouter type
  • react-query-setup -- use tRPC with TanStack React Query for React applications

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.95%
按下载量换算52

Claude

29.78%
按下载量换算44

Cursor

18.08%
按下载量换算27

Gemini CLI

7.95%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills