GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - martin1847/krpc: Agent-native RPC for the multi-agent era — write a Java interface, get gRPC + HTTP/MCP gateway and generated TS/Dart/Python/Rust clients, no protobuf. 智能体时代的契约先行 RPC:接口即 API,天然带 MCP 网关

BranchesTags
Open more actions menu

Latest commit

 

History

651 Commits
651 Commits

Folders and files

NameName
Last commit message
Last commit date
.ai
.ai
 
 
.claude
.claude
 
 
.githooks
.githooks
 
 
.github
.github
 
 
arch-test
arch-test
 
 
benchmark
benchmark
 
 
docs-site
docs-site
 
 
docs
docs
 
 
examples/quickstart
examples/quickstart
 
 
ext-rpc-gen
ext-rpc-gen
 
 
gradle
gradle
 
 
http-server
http-server
 
 
proto
proto
 
 
rpc-api
rpc-api
 
 
rpc-client-spring
rpc-client-spring
 
 
rpc-client
rpc-client
 
 
rpc-common
rpc-common
 
 
rpc-server-quarkus
rpc-server-quarkus
 
 
rpc-server-spring
rpc-server-spring
 
 
rpc-server
rpc-server
 
 
skills/krpc
skills/krpc
 
 
test-api
test-api
 
 
test-jwks
test-jwks
 
 
test-server-spring
test-server-spring
 
 
test-server
test-server
 
 
.gitguardian.yaml
.gitguardian.yaml
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
ARCHITECTURE.png
ARCHITECTURE.png
 
 
CLAUDE.md
CLAUDE.md
 
 
CODE-OF-CONDUCT.md
CODE-OF-CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
EVIDENCE-20260719-0049-iac-otel003-mesh-confirmed.md
EVIDENCE-20260719-0049-iac-otel003-mesh-confirmed.md
 
 
EVIDENCE-20260719-0112-iac-otel-fullcase-closed.md
EVIDENCE-20260719-0112-iac-otel-fullcase-closed.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
README.zh-CN.md
README.zh-CN.md
 
 
SECURITY.md
SECURITY.md
 
 
SPEC.md
SPEC.md
 
 
build.gradle
build.gradle
 
 
changelog.md
changelog.md
 
 
decomposing.png
decomposing.png
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
llms.txt
llms.txt
 
 
loss.md
loss.md
 
 
packageIcon.png
packageIcon.png
 
 
refresh.sh
refresh.sh
 
 
renovate.json
renovate.json
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

KRPC

One Java interface → gRPC · HTTP · typed clients · MCP tools

简体中文

What is KRPC

KRPC is a contract-first, agent-native RPC framework for the JVM (JDK 21): you write one Java interface plus DTOs — no hand-written .proto — and the framework turns that single contract into a gRPC/HTTP2 service, a JSON HTTP API, typed clients for TypeScript / Dart / Python, and an opt-in MCP tool surface that AI agents call directly.

The Java interface is the source of truth. KRPC handles transport, JSON serialization, jakarta validation, runtime metadata, and client generation, so service authors write business logic — not schemas, stubs, or boilerplate.

KRPC leans on the platform instead of rebuilding it: service discovery, load balancing, telemetry, ingress TLS, and mesh policy stay with Kubernetes, Istio, gateway, or deployment infrastructure (ADR-0001). It is used in production in e-commerce, education, and local-service products.

KRPC architecture: one Java interface exposed as a gRPC face, an HTTP face, generated clients and MCP tools; discovery, load balancing and telemetry delegated to the platform

Source: docs/assets/architecture.svg (light) and architecture-dark.svg; ports and paths follow SPEC §16.2.

Why the agent era needs it

In the agent era, services are no longer called only by other services — agents call them as tools. A KRPC Java interface is simultaneously the RPC contract and, when you opt in, the MCP tool surface an AI agent invokes. One annotated interface serves a browser, a service-to-service caller, a generated TS/Dart client, and an LLM agent — from a single definition, with no separate tool-wrapping layer.

The mechanism is KRPC's runtime self-description (ADR-0004). Every server exposes ApiMeta — service and method signatures, full DTO type trees, @Doc documentation, and validation constraints — which powers three agent-facing HTTP surfaces:

  • GET /agent/discover — the web-visible ApiMeta as JSON, so an agent can introspect a live service (agent guide).
  • POST /agent/invoke — resolve Service/method, forward JSON, and dispatch through the same credential and filter path as a gRPC call.
  • POST /mcp — a hand-written Model Context Protocol bridge (spec 2025-06-18, JSON-RPC 2.0 over Streamable HTTP; no third-party SDK), whose tools/list / tools/call are generated from the same ApiMeta (SPEC §12.2).

Exposure is layered and default-safe. A service is internal (hidden) unless annotated @UnsafeWeb; only @UnsafeWeb(agentTool=true) — or method-level @UnsafeWeb.AgentTool — opts a method into the MCP tool set, and @UnsafeWeb alone never creates a tool. The tool attribute defaults to false, and the MCP bridge itself is off by default (rpc.server.mcp.enabled=false, env KRPC_MCP), so a disabled deployment ships zero new wire surface. Credentials are never bypassed on the agent path.

AI agent? Install the krpc skill and read the agent guide to discover and call KRPC services over HTTP.

How it differs from protobuf-gRPC

  • No hand-written .proto. The Java interface and its DTOs are the contract (enforced at method discovery in RefUtils); there is no separate IDL to keep in sync.
  • JSON by default. The transport is gRPC/HTTP2, but the default codec is JSON for broad client reach. On the wire, payloads ride a fixed InputProto/OutputProto envelope (JSON or bytes inside) rather than a per-message protobuf schema (SPEC §14).
  • HTTP + gRPC dual face. A gRPC gateway (rpc.server.port, default 50051) and a plain-HTTP server (http.port, default 8080, serving /agent/* and /mcp) run in the same process.
  • GraalVM native, JDK 21, virtual threads. First-class native-image support via the Quarkus integration (SPEC §13); blocking handlers run on virtual threads (ADR-0002).
  • gRPC interop, honestly. Because the wire uses KRPC's generic envelope, a stock protobuf-generated gRPC stub does not interoperate directly — you call via a KRPC-generated client, rpcurl, the HTTP /agent face, or MCP. The gRPC path has no runtime schema handshake (RPCURL-001); introspect over GET /agent/discover instead.

FAQ

Is KRPC compatible with existing gRPC / protobuf clients? Not directly. KRPC uses gRPC/HTTP2 as transport but carries a fixed InputProto/OutputProto envelope with JSON (or bytes) inside, not per-service protobuf messages — so a stub generated from a hand-written .proto cannot call a KRPC service as-is. Call it through a KRPC-generated client (Java/TS/Dart/Python), rpcurl, the HTTP /agent/invoke endpoint, or the MCP bridge.

Do I need .proto files? No. For normal business APIs you write a Java interface returning RpcResult<Dto> plus DTOs; that interface is the contract and the source for client generation. KRPC uses protobuf only as an internal wire envelope, never as an author-facing IDL.

How do agents / MCP clients call a KRPC service? Enable the MCP bridge (KRPC_MCP=true) and mark the methods you want to expose with @UnsafeWeb(agentTool=true) (or @UnsafeWeb.AgentTool per method); an MCP client then does tools/list + tools/call over POST /mcp. Agents that don't speak MCP can GET /agent/discover for the JSON schema and POST /agent/invoke to call a method. Both paths run the same credential checks as gRPC.

What does the generated TypeScript / Dart client give me? A typed client derived from the same interface + DTOs, so a frontend or mobile app calls methods with exact request/response types (and @Doc docs) — no manual HTTP wiring, no separately maintained schema. Clients also exist for Python, Go/k6, Java, and rpcurl.

Does it run as a GraalVM native image? Yes, via the rpc-server-quarkus integration (SPEC §13); the quickstart is verified building and booting as a native binary. Mind the documented native-reflection pitfalls (e.g. Caffeine bounded caches) when adding libraries.

How does it compare to Spring gRPC / protobuf-gRPC? KRPC drops the .proto/IDL step (interfaces are the contract), defaults to JSON, and adds a JSON HTTP face plus agent/MCP introspection on top of the gRPC transport. Classic protobuf-gRPC gives you schema-first cross-language contracts and direct protobuf interop; KRPC trades that for interface-first ergonomics and agent-native surfaces on the JVM.

What JDK and framework does it need? JDK 21 (virtual threads are a supported runtime feature, not a roadmap item) and Gradle. The runtime is framework-agnostic, with ready integrations for Quarkus (rpc-server-quarkus, incl. native) and Spring (rpc-server-spring / rpc-client-spring).

How do I expose only some methods as agent tools? Exposure is opt-in and layered. Leave a service unannotated to keep it internal; add @UnsafeWeb to reach it from browsers/HTTP; add agentTool=true at the interface level, or @UnsafeWeb.AgentTool on individual methods, to publish exactly those methods as MCP tools. Defaults are all-OFF, and the MCP bridge stays off unless KRPC_MCP is set.

Try It Live

A public sandbox runs the quickstart natively at https://demo.krpc.tech — no local build needed. HelloService only, with fake data. nginx is the only entry point.

MCP (JSON-RPC 2.0 over Streamable HTTP) — list the tools, then call one:

curl -sS https://demo.krpc.tech/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

curl -sS https://demo.krpc.tech/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"Hello_hello","arguments":{"name":"you"}}}'

HTTP introspection — the web-only ApiMeta:

curl -sS https://demo.krpc.tech/agent/discover

rpcurl (needs >=1.1.0 for the https discover path):

rpcurl discover https://demo.krpc.tech
rpcurl https://demo.krpc.tech/quickstart/Hello/hello -d '{"name":"you"}'

Public fake-data sandbox — may reset anytime. Error-envelope demo: call Hello_hello with {} (empty args) to see {code,message,violations}, e.g. {"code":3,"message":"Invalid input","violations":[{"field":"name","constraint":"must not be blank"}]}.

Modules

  • rpc-api: annotations and shared API models.
  • rpc-common: serialization, context, filters, metadata, and utilities.
  • rpc-client: Java client runtime.
  • rpc-server: Java server runtime.
  • rpc-client-spring: Spring client integration.
  • rpc-server-spring: Spring server integration.
  • rpc-server-quarkus: Quarkus and native-image integration.
  • http-server: HTTP gateway support.
  • test-rpc-gen: client code generation examples.

The command-line rpcurl client is a separate Rust project — see Call With rpcurl.

Requirements

  • JDK 21
  • Gradle

Latest version: 1.2.0 (see the support policy for the version/support matrix and SPEC.md for the authoring handbook).

implementation "tech.krpc:rpc-api:1.2.0"
implementation "tech.krpc:rpc-client:1.2.0"
implementation "tech.krpc:rpc-server:1.2.0"

Define An API

Add rpc-api to the API module:

plugins {
    id "org.kordamp.gradle.jandex" version "2.0.0"
}

dependencies {
    api "tech.krpc:rpc-api:1.2.0"
}

Define services as Java interfaces:

@RpcService
public interface DemoService {
    RpcResult<HelloResult> hello(HelloReq req);
}

public class HelloReq {
    @Doc("name")
    @NotBlank
    private String name;
}

API rules:

  • Return RpcResult<DTO>.
  • Use one input object per method.
  • Use DTOs for request and response bodies.
  • Use jakarta.validation for input validation.
  • Use @Doc for fields that need generated client documentation.
  • Avoid Map in API contracts unless there is a strong reason.
  • Avoid enum fields in response DTOs when long-term client stability matters.

Publish API artifacts with semantic versions. Avoid SNAPSHOT for shared API packages.

Implement A Server

Add the API and server runtime:

dependencies {
    implementation project(":your-api")
    implementation "tech.krpc:rpc-server:1.2.0"
}

Implement the interface:

@ApplicationScoped
@Startup
public class DemoServiceImpl implements DemoService {
    @Override
    public RpcResult<HelloResult> hello(HelloReq req) {
        return RpcResult.ok(new HelloResult("hello " + req.getName()));
    }
}

Call With rpcurl

rpcurl is available from martin1847/krpc-crates.

export KRPC_APP="https://example.com/demo"

rpcurl "$KRPC_APP/Demo/hello" -d '{"name":"krpc"}'

Common options:

-d, --data <DATA>      request JSON
-f, --file <FILE>      request JSON file
-t, --token <TOKEN>    Authorization: Bearer token
-c, --cookie <COOKIE>  Cookie header
-H, --header <HEADER>  custom header, e.g. -H a=b
-v, --verbose          verbose output

Error Handling

Use soft errors for business failures:

  • Server: return RpcResult with a non-OK code and message.
  • Client: check isOk() before reading data.

Use exceptions for system failures, security failures, validation failures, and unexpected runtime errors.

Quickstart (5 minutes)

The fastest way to see KRPC run — a single module, no database, no JWT:

gradle :examples:quickstart:run

Then call it:

rpcurl http://127.0.0.1:50051/quickstart/Hello/hello -d '{"name":"krpc"}'

See examples/quickstart/ for the walkthrough.

Run Existing Demo

The repository includes an integration demo in test-api and test-server.

Build it:

gradle :test-server:build -x test

Run it:

gradle :test-server:quarkusDev \
  -Dquarkus.datasource.password=youshallnotpass \
  -Ddebug=false \
  --console=plain

Call it:

rpcurl http://127.0.0.1:50051/test-server/Demo/hello \
  -d '{"name":"krpc","age":18}'

This is an integration demo, not a minimal quickstart template. It includes MySQL, MyBatis, and JWKS-related configuration; local JWKS fetch warnings do not block the Demo/hello call.

Clients

Generated or companion clients exist for Dart, TypeScript, Python, Go/k6, Java, and rpcurl.

Project Governance

  • Documentation index: docs/INDEX.md
  • Repository scope: ADR-0001
  • JDK 21 and virtual threads: ADR-0002

About

Agent-native RPC for the multi-agent era — write a Java interface, get gRPC + HTTP/MCP gateway and generated TS/Dart/Python/Rust clients, no protobuf. 智能体时代的契约先行 RPC:接口即 API,天然带 MCP 网关

krpc.tech

Topics

agent-nativeai-agentscontract-firstgraalvmgrpcjavamcpmicroservicesmulti-agentprotobuf-freequarkusrpc

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

4 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.