MCPcopy
hub / github.com/connectrpc/connect-es

github.com/connectrpc/connect-es @v2.1.2 sqlite

repository ↗ · DeepWiki ↗ · release v2.1.2 ↗
1,132 symbols 2,946 edges 399 files 67 documented · 6%
README

Connect for ECMAScript

License Build NPM Version

Connect is a family of libraries for building type-safe APIs with different languages and platforms. @connectrpc/connect brings them to TypeScript, web browsers, and Node.js.

A small example

With Connect, we define our schema first:

service ElizaService {
  rpc Say(SayRequest) returns (SayResponse) {}
}

And with the magic of code generation, we can implement and serve our service:

import * as http from "node:http";
import type { ConnectRouter } from "@connectrpc/connect";
import { connectNodeAdapter } from "@connectrpc/connect-node";
import { createValidateInterceptor } from "@connectrpc/validate";
import type { SayRequest } from "./gen/eliza_pb.js";
import { ElizaService } from "./gen/eliza_pb.js";

// The adapter turns our RPC routes into a Node.js request handler.
const handler = connectNodeAdapter({
  // Validation via Protovalidate is almost always recommended
  interceptors: [createValidateInterceptor()],
  routes: (router: ConnectRouter) => {
    router.service(ElizaService, {
      say(req: SayRequest) {
        return {
          sentence: `You said "${req.sentence}"`,
        };
      },
    });
  },
});

http.createServer(handler).listen(8080)

Calling an RPC is just as simple. You create a client with your server's URL and call a method:

import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_pb.js";

const client = createClient(
  ElizaService,
  createConnectTransport({
    httpVersion: "1.1",
    baseUrl: "http://localhost:8080",
  })
);

try {
  const res = await client.say({sentence: "Hello, world!"})
  console.log(res.sentence)
} catch (err) {
  console.error(err);
}

Of course, a plain HTTP server isn't fit for production use! See Connect's server plugins for a guide to production deployment with Fastify, Next.js, Express, and more.

Simple, cURL-friendly RPC protocol

Unlike REST, the Remote Procedure Calls are type-safe, but they are regular HTTP under the hood. You can see all requests in the network inspector, and you can curl them if you want:

curl \
    --header 'Content-Type: application/json' \
    --data '{"sentence": "I feel happy."}' \
    https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

Connect uses Protobuf-ES, the only fully-compliant Protobuf JavaScript library.

Connect implements three RPC protocols: The widely available gRPC and gRPC-web protocols, and Connect's own protocol, optimized for the web. This gives you unparalleled interoperability across many platforms and languages, with type safety end-to-end.

Get started on the web

Follow our 10-minute tutorial where we use Vite and React to create a web interface for ELIZA.

For other frameworks, such as Svelte, Vue, Next.js and Angular, see our examples. For TanStack Query, see our expansion pack Connect-Query.

Get started on Node.js

Follow our 10-minute tutorial to spin up a service in Node.js, and call it from the web, and from a gRPC client in your terminal.

You can serve your Connect RPCs with vanilla Node.js, or use our server plugins for Fastify, Next.js, and Express.

Migrating from version 1

If you are migrating from v1 to v2, check out our migration guide.

Other platforms

Would you like to use Connect on other platforms like Bun, Deno, Vercel’s Edge Runtime, or Cloudflare Workers? We’d love to learn about your use cases and what you’d like to do with Connect. You can reach us either through the Buf Slack or by filing a GitHub issue and we’d be more than happy to chat!

Packages

Ecosystem

Compatibility

All maintained releases of Node.js (Current, Active LTS, and the Maintenance LTS release) are supported.

Baseline web browsers from the last 2.5 years are supported.

Same as Definitely Typed, we support versions of TypeScript that are less than 2 years old, with default compiler settings. Note that for some changes in TypeScript, it is impossible to support both new and old versions in the support window. We break the tie by supporting the newer version.

Status

This project is stable and follows semantic versioning, which means any breaking changes will result in a major version increase. Our goal is to not make breaking changes unless absolutely necessary.

Legal

Offered under the Apache 2 license.

Extension points exported contracts — how you extend this code

StateClosed (Interface)
* The connection is closed, or no connection has been opened yet.
packages/connect-node/src/http2-session-manager.ts
HandlerContextInit (Interface)
* Options for creating a HandlerContext.
packages/connect/src/implementation.ts
NextJsApiRouterOptions (Interface)
(no doc)
packages/connect-next/src/connect-nextjs-adapter.ts
FastifyConnectPluginOptions (Interface)
(no doc)
packages/connect-fastify/src/fastify-connect-plugin.ts
ConnectTransportOptions (Interface)
(no doc)
packages/connect-web/src/connect-transport.ts
ExpressConnectMiddlewareOptions (Interface)
(no doc)
packages/connect-express/src/express-connect-middleware.ts
CommandLineArgs (Interface)
(no doc)
packages/connect-migrate/src/arguments.ts
WorkerHandlerOptions (Interface)
(no doc)
packages/connect-cloudflare/conformance/handler.ts

Core symbols most depended-on inside this repo

get
called by 186
packages/connect/src/context-values.ts
set
called by 107
packages/connect/src/context-values.ts
from
called by 103
packages/connect/src/connect-error.ts
abort
called by 93
packages/connect/src/implementation.ts
createAsyncIterable
called by 86
packages/connect/src/protocol/async-iterable.ts
log
called by 70
packages/connect-migrate/src/lib/logger.ts
close
called by 68
packages/connect-migrate/src/lib/logger.ts
state
called by 66
packages/connect-node/src/http2-session-manager.ts

Shape

Function 557
Class 370
Enum 96
Interface 64
Method 45

Languages

TypeScript100%

Modules by API surface

packages/connect-node/src/http2-session-manager.ts51 symbols
packages/connect/src/protocol/async-iterable.ts35 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/module/v1beta1/module_service_pb.d.ts28 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/module/v1beta1/label_service_pb.d.ts28 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/module/v1/module_service_pb.d.ts28 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/module/v1/label_service_pb.d.ts28 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/owner/v1/user_service_pb.d.ts27 symbols
packages/connect-web-bench/src/gen/grpcweb/buf/registry/owner/v1/organization_service_pb.d.ts26 symbols
packages/connect-node/src/node-universal-client.ts25 symbols
packages/connect/src/protocol/envelope.ts17 symbols
packages/connect/src/protocol/universal-fetch.ts15 symbols
packages/connect/src/protocol/serialization.ts14 symbols

Dependencies from manifests, versioned

@arethetypeswrong/cli0.18.2 · 1×
@biomejs/biome1.9.4 · 1×
@bufbuild/buf1.66.1 · 1×
@bufbuild/license-header0.0.4 · 1×
@bufbuild/protobuf2.7.0 · 1×
@bufbuild/protoc-gen-es2.10.0 · 1×
@cloudflare/workers-types4.20260609.1 · 1×
@connectrpc/connect2.1.2 · 1×
@connectrpc/connect-conformance* · 1×
@connectrpc/connect-node2.1.2 · 1×
@connectrpc/connect-web2.1.2 · 1×

For agents

$ claude mcp add connect-es \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact