Coverage for mcpgateway / plugins / framework / external / grpc / __init__.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 03:05 +0000

1# -*- coding: utf-8 -*- 

2"""Location: ./mcpgateway/plugins/framework/external/grpc/__init__.py 

3Copyright 2025 

4SPDX-License-Identifier: Apache-2.0 

5Authors: Teryl Taylor 

6 

7gRPC transport for external plugins. 

8 

9This package provides gRPC-based communication between ContextForge and 

10external plugin servers. It offers a faster binary protocol alternative to 

11the MCP/HTTP transport while maintaining the same plugin semantics. 

12 

13Usage: 

14 Client (Gateway side): 

15 Configure a plugin with the `grpc:` section instead of `mcp:`: 

16 

17 ```yaml 

18 plugins: 

19 - name: "MyPlugin" 

20 kind: "external" 

21 hooks: ["tool_pre_invoke"] 

22 grpc: 

23 target: "localhost:50051" 

24 tls: 

25 verify: true 

26 ca_bundle: /path/to/ca.pem 

27 ``` 

28 

29 Server (Plugin side): 

30 Run the gRPC server to expose your plugins: 

31 

32 ```bash 

33 python -m mcpgateway.plugins.framework.external.grpc.server.runtime \\ 

34 --config plugins/config.yaml \\ 

35 --port 50051 

36 ``` 

37 

38Exports: 

39 GrpcExternalPlugin: Client-side plugin that connects to gRPC server. 

40 GrpcPluginServicer: Server-side gRPC servicer. 

41 GrpcHealthServicer: Health check servicer. 

42 create_client_credentials: Helper to create gRPC client TLS credentials. 

43 create_server_credentials: Helper to create gRPC server TLS credentials. 

44 

45Note: 

46 gRPC plugins use the existing ExternalHookRef from the MCP transport since 

47 both transports share the same invoke_hook() interface. 

48""" 

49 

50from mcpgateway.plugins.framework.external.grpc.client import GrpcExternalPlugin 

51from mcpgateway.plugins.framework.external.grpc.tls_utils import create_client_credentials, create_server_credentials 

52 

53__all__ = [ 

54 "GrpcExternalPlugin", 

55 "create_client_credentials", 

56 "create_server_credentials", 

57] 

58 

59# Server exports are imported lazily to avoid circular imports 

60# Import here after client to ensure proper initialization order 

61from mcpgateway.plugins.framework.external.grpc.server import GrpcHealthServicer, GrpcPluginServicer # noqa: E402, F401 

62 

63__all__.extend(["GrpcPluginServicer", "GrpcHealthServicer"])