MCPcopy Index your code
hub / github.com/ktr0731/evans

github.com/ktr0731/evans @0.10.11

repository ↗ · DeepWiki ↗ · release 0.10.11 ↗ · + Follow
597 symbols 1,853 edges 108 files 203 documented · 34% updated 2y agov0.10.11 · 2023-02-26★ 4,48322 open issues
README

Evans


GitHub Actions codecov PkgGoDev

Motivation

Evans has been created to use easier than other existing gRPC clients.
If you want to keep your product quality, you must use CI with gRPC testing, should not do use manual testing.
Evans will complete your other use cases just like:

  • Manually gRPC API inspection
  • To automate some tasks by scripting

The above use cases are corresponding to Evans's two modes, REPL mode, and CLI mode.

REPL mode

Evans
REPL mode is the solution for first use case.
You can use it without thinking like the package name, service name, RPC name, command usage, and so on because REPL mode has powerful completion!

CLI mode

Evans

CLI mode is a stateless mode just like grpc-ecosystem/polyglot.
It sends one request per one command as its name suggests.
So it is based on UNIX philosophy.

For example, read inputs from stdin, the command will be a filter command.
On the other hand, the command result will be outputted to stdout by JSON formatted.
So, you can format it by any commands like jq. Also, if you want to use the same command (e.g. use same JSON inputs), you can use --file (-f) option.

Table of Contents

Installation

Highly recommended methods are GitHub Releases or Homebrew because these can be updated automatically by the built-in feature in Evans.

From GitHub Releases

Please see GitHub Releases.
Available binaries are: - macOS - Linux - Windows

macOS

brew tap ktr0731/evans
brew install evans

Docker image

You can use our docker image to run Evans - please see container registry. For example, if you want to connect to the server on host example.com on port 50051 using proto file in ./proto/files/file-name.proto (default working directory is /mount):

$ docker run --rm -v "$(pwd):/mount:ro" \
    ghcr.io/ktr0731/evans:latest \
      --path ./proto/files \
      --proto file-name.proto \
      --host example.com \
      --port 50051 \
      repl

[Not-recommended] go install

Go v1.20 or later is required.

go install github.com/ktr0731/evans@latest

Usage (REPL)

Basic usage

Evans consists of some commands in REPL mode.

The proto file which read in the demonstration and its implementation are available at ktr0731/grpc-test.
grpc-test's details can see grpc-test --help.

Enter to REPL.

cd grpc-test
evans --proto api/api.proto repl

If your server is enabling gRPC reflection, you can launch Evans with only -r (--reflection) option.

evans -r repl

Also if the server requires secure TLS connections, you can launch Evans with the -t (--tls) option.

evans --tls --host example.com -r repl

To show package names of proto files REPL read:

> show package
+---------+
| PACKAGE |
+---------+
| api     |
+---------+

To show the summary of services or messages:

> package api
> show service
+---------+----------------------+-----------------------------+----------------+
| SERVICE |         RPC          |         REQUESTTYPE         |  RESPONSETYPE  |
+---------+----------------------+-----------------------------+----------------+
| Example | Unary                | SimpleRequest               | SimpleResponse |
|         | UnaryMessage         | UnaryMessageRequest         | SimpleResponse |
|         | UnaryRepeated        | UnaryRepeatedRequest        | SimpleResponse |
|         | UnaryRepeatedMessage | UnaryRepeatedMessageRequest | SimpleResponse |
|         | UnaryRepeatedEnum    | UnaryRepeatedEnumRequest    | SimpleResponse |
|         | UnarySelf            | UnarySelfRequest            | SimpleResponse |
|         | UnaryMap             | UnaryMapRequest             | SimpleResponse |
|         | UnaryMapMessage      | UnaryMapMessageRequest      | SimpleResponse |
|         | UnaryOneof           | UnaryOneofRequest           | SimpleResponse |
|         | UnaryEnum            | UnaryEnumRequest            | SimpleResponse |
|         | UnaryBytes           | UnaryBytesRequest           | SimpleResponse |
|         | ClientStreaming      | SimpleRequest               | SimpleResponse |
|         | ServerStreaming      | SimpleRequest               | SimpleResponse |
|         | BidiStreaming        | SimpleRequest               | SimpleResponse |
+---------+----------------------+-----------------------------+----------------+

> show message
+-----------------------------+
|           MESSAGE           |
+-----------------------------+
| SimpleRequest               |
| SimpleResponse              |
| Name                        |
| UnaryMessageRequest         |
| UnaryRepeatedRequest        |
| UnaryRepeatedMessageRequest |
| UnaryRepeatedEnumRequest    |
| UnarySelfRequest            |
| Person                      |
| UnaryMapRequest             |
| UnaryMapMessageRequest      |
| UnaryOneofRequest           |
| UnaryEnumRequest            |
| UnaryBytesRequest           |
+-----------------------------+

To show more description of a message:

> desc SimpleRequest
+-------+-------------+
| FIELD |    TYPE     |
+-------+-------------+
| name  | TYPE_STRING |
+-------+-------------+

Set headers for each request:

> header foo=bar

To show headers:

> show header
+-------------+-------+
|     KEY     |  VAL  |
+-------------+-------+
| foo         | bar   |
| grpc-client | evans |
+-------------+-------+

Note that if you want to set comma-included string to a header value, it is required to specify --raw option.

To remove the added header:

> header foo
> show header
+-------------+-------+
|     KEY     |  VAL  |
+-------------+-------+
| grpc-client | evans |
+-------------+-------+

Call a RPC:

> service Example
> call Unary
name (TYPE_STRING) => ktr
{
  "message": "hello, ktr"
}

Evans constructs a gRPC request interactively and sends the request to a gRPC server.
Finally, Evans prints the JSON formatted result.

Repeated fields

repeated is an array-like data structure.
You can input some values and finish with CTRL-D

> call UnaryRepeated
<repeated> name (TYPE_STRING) => foo
<repeated> name (TYPE_STRING) => bar
<repeated> name (TYPE_STRING) => baz
<repeated> name (TYPE_STRING) =>
{
  "message": "hello, foo, bar, baz"
}

Enum fields

You can select one from the proposed selections.
When CTRL-C is entered, default value 0 will be used.
When CTRL-D is entered, inputting will be aborted.

> call UnaryEnum
? UnaryEnumRequest  [Use arrows to move, type to filter]
> Male
  Female
{
  "message": "M"
}

Bytes type fields

You can pass bytes as a base64-encoded string.

> call UnaryBytes
data (TYPE_BYTES) => SGVsbG8gV29ybGQh
{
  "message": "received: (bytes) 48 65 6c 6c 6f 20 57 6f 72 6c 64 21, (string) Hello World!"
}

⚠️ Warning: Previously, bytes were passed as a (quoted) byte literal or Unicode literal string.

While evans currenty still attempts to fall back to that encoding if decoding as base64 fails, it's discouraged, and might be dropped.

Please either encode bytes as base64, or pass --bytes-as-quoted-literals explicitly:

> call UnaryBytes --bytes-as-quoted-literals
data (TYPE_BYTES) => \x46\x6f\x6f
{
  "message": "received: (bytes) 46 6f 6f, (string) Foo"
}

> call UnaryBytes --bytes-as-quoted-literals
data (TYPE_BYTES) => \u65e5\u672c\u8a9e
{
  "message": "received: (bytes) e6 97 a5 e6 9c ac e8 aa 9e, (string) 日本語"
}

You can also add the flag --bytes-as-base64 to explicitly disable the fallback behaviour.

Or add the flag --bytes-from-file to read bytes from the provided relative path

> call UnaryBytes --bytes-from-file
data (TYPE_BYTES) => ../relative/path/to/file

Client streaming RPC

Client streaming RPC accepts some requests and then returns only one response.
Finish request inputting with CTRL-D

> call ClientStreaming
name (TYPE_STRING) => ktr
name (TYPE_STRING) => ktr
name (TYPE_STRING) => ktr
name (TYPE_STRING) =>
{
  "message": "ktr, you greet 3 times."
}

Server streaming RPC

Server streaming RPC accepts only one request and then returns some responses. Each response is represented as another JSON formatted output.

name (TYPE_STRING) => ktr
{
  "message": "hello ktr, I greet 0 times."
}

{
  "message": "hello ktr, I greet 1 times."
}

Bidirectional streaming RPC

Bidirectional streaming RPC accepts some requests and returns some responses corresponding to each request. Finish request inputting with CTRL-D

> call BidiStreaming
name (TYPE_STRING) => foo
{
  "message": "hello foo, I greet 0 times."
}

{
  "message": "hello foo, I greet 1 times."
}

{
  "message": "hello foo, I greet 2 times."
}

name (TYPE_STRING) => bar
{
  "message": "hello bar, I greet 0 times."
}

name (TYPE_STRING) =>

Skip the rest of the fields

Evans recognizes CTRL-C as a special key that skips the rest of the fields in the current message type. For example, we assume that we are inputting Request described in the following message:

message FullName {
  string first_name = 1;
  string last_name = 2;
}

message Request {
  string nickname = 1;
  FullName full_name = 2;
}

If we enter CTRL-C at the following moment, full_name field will be skipped.

nickname (TYPE_STRING) =>

The actual request value is just like this.

{}

If we enter CTRL-C at the following moment, last_name field will be skipped.

nickname (TYPE_STRING) => myamori
full_name::first_name (TYPE_STRING) => aoi
full_name::last_name (TYPE_STRING) =>

The actual request value is just like this.

{
  "nickname": "myamori",
  "fullName": {
    "firstName": "aoi"
  }
}

By default, Evans digs down each message field automatically.
For example, we assume that we are inputting Request described in the following message:

message FullName {
  string first_name = 1;
  string last_name = 2;
}

message Request {
  FullName full_name = 1;
}

In this case, REPL prompts full_name.first_name automatically. To skip full_name itself, we can use --dig-manually option. It asks whether dig down a message field when the prompt encountered it.

Enriched response

To display more enriched response, you can use --enrich option.

> call --enrich Unary
name (TYPE_STRING) => ktr
content-type: application/grpc
header_key1: header_val1
header_key2: header_val2

{
  "message": "hello, ktr"
}

trailer_key1: trailer_val1
trailer_key2: trailer_val2

code: OK
number: 0
message: ""

Repeat the previous call

With --repeat option, you can repeat the previous call with the same input.
Note that Client/Bidirectional streaming RPC is not supported.

> call Unary
name (TYPE_STRING) => ktr
{
  "message": "hello, ktr"
}

> call --repeat Unary
name (TYPE_STRING) => ktr
{
  "message": "hello, ktr"
}

Usage (CLI)

Basic usage

CLI mode also has some commands.

list command provides gRPC service inspection against to the gRPC server.

$ evans -r cli list
api.Example
grpc.reflection.v1alpha.ServerReflection

If an service name is specified, it displays methods belonging to the service.

$ evans -r cli list api.Example
api.Example.Unary
api.Example.UnaryBytes
api.Example.UnaryEnum
...

desc command describes the passed symbol (service, method, message, and so on).

api.Example:
service Example {
  rpc Unary ( .api.SimpleRequest ) returns ( .api.SimpleResponse );
  rpc UnaryBytes ( .api.UnaryBytesRequest ) returns ( .api.SimpleResponse );
  rpc UnaryEnum ( .api.UnaryEnumRequest ) returns ( .api.SimpleResponse );
  ...
}

call command invokes a method. You can input requests from stdin or files.

Use --file (-f) to specify a file. ``

Extension points exported contracts — how you extend this code

Presenter (Interface)
Presenter formats response types returned from the gRPC server for displaying it. [4 implementers]
present/present.go
Filler (Interface)
Filler tries to correspond input text to a struct. [3 implementers]
fill/filler.go
ResponseFormatterInterface (Interface)
ResponseFormatterInterface is an interface for formatting gRPC response. [3 implementers]
format/format.go
Completer (Interface)
Completer is a mechanism that provides REPL completion. [2 implementers]
prompt/prompt.go
Spec (Interface)
Spec represents the interface specification from loaded IDL files. [2 implementers]
idl/idl.go
ServerStream (Interface)
(no doc) [3 implementers]
grpc/grpc.go
UI (Interface)
UI provides formatted I/O interfaces. It is used from Evans's standard I/O and CLI mode I/O. [1 implementers]
cui/ui.go
CLIInvoker (FuncType)
CLIInvoker represents an invokable function for CLI mode.
mode/cli.go

Core symbols most depended-on inside this repo

Run
called by 66
repl/commands.go
String
called by 38
usecase/call_rpc.go
Printf
called by 21
logger/logger.go
Writer
called by 20
cui/ui.go
NewSuggestion
called by 18
prompt/prompt.go
Close
called by 15
grpc/grpc.go
Code
called by 14
usecase/call_rpc.go
Error
called by 12
cui/ui.go

Shape

Method 284
Function 207
Struct 82
Interface 15
TypeAlias 6
FuncType 3

Languages

Go100%

Modules by API surface

grpc/grpc.go49 symbols
repl/commands.go42 symbols
prompt/prompt.go34 symbols
config/config.go26 symbols
grpc/web.go24 symbols
cui/ui.go18 symbols
usecase/call_rpc.go15 symbols
fill/proto/interactive_filler.go14 symbols
config/config_test.go14 symbols
app/update_test.go14 symbols
format/format.go13 symbols
e2e/e2egen/mock_gen.go13 symbols

Dependencies from manifests, versioned

cloud.google.com/gov0.104.0 · 1×
cloud.google.com/go/computev1.12.1 · 1×
cloud.google.com/go/compute/metadatav0.2.1 · 1×
cloud.google.com/go/kmsv1.4.0 · 1×
cloud.google.com/go/storagev1.23.0 · 1×
github.com/AlekSi/pointerv1.2.0 · 1×
github.com/Azure/azure-pipeline-gov0.2.3 · 1×
github.com/Azure/azure-sdk-for-gov60.2.0+incompatible · 1×
github.com/Azure/azure-storage-blob-gov0.14.0 · 1×
github.com/Azure/go-autorestv14.2.0+incompatible · 1×

For agents

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

⬇ download graph artifact