A


[](https://fuchsia.dev/docs/glossary#protocol-capability)


is a capability backed
by a


[](https://fuchsia.dev/docs/glossary#channel)


that speaks a particular


[](https://fuchsia.dev/docs/glossary#protocol)


.

    library fuchsia.examples;

    const MAX_STRING_LENGTH uint64 = 32;

    @discoverable
    protocol Echo {
        EchoString(struct {
            value string:MAX_STRING_LENGTH;
        }) -> (struct {
            response string:MAX_STRING_LENGTH;
        });
        SendString(struct {
            value string:MAX_STRING_LENGTH;
        });
        -> OnString(struct {
            response string:MAX_STRING_LENGTH;
        });
    };

> [!NOTE]
> **Note:** For more details on FIDL protocol syntax, see the [FIDL language reference](https://fuchsia.dev/docs/reference/fidl/language/language).

Protocol implementations are served from provider components using the


[](https://fuchsia.dev/docs/glossary#outgoing-directory)


and consumed from another
component's


[](https://fuchsia.dev/docs/glossary#namespace)


.

## Providing protocol capabilities

To provide a protocol capability, a component must declare the capability and
[route](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/protocol#route) it from `self`. The component hosts the protocol capability in
its


[](https://fuchsia.dev/docs/glossary#outgoing-directory)


.

To define the capability, add a `capabilities` declaration for it:

    {
        capabilities: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
            },
        ],
    }

This defines a capability hosted by this component whose outgoing directory path
is `/svc/fuchsia.example.ExampleProtocol`. You can also customize the path:

    {
        capabilities: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
                path: "/my_svc/fuchsia.example.MyExampleProtocol",
            },
        ],
    }

## Routing protocol capabilities

Components route protocol capabilities by [exposing](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/protocol#expose) them to their
parent and [offering](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/protocol#offer) them to their children.

For more details on how the framework routes component capabilities,
see [capability routing](https://fuchsia.dev/docs/concepts/components/v2/capabilities/README#routing).

### Exposing

Exposing a protocol capability gives the component's parent access to that
capability:

    {
        expose: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
                from: "self",
            },
        ],
    }

The `from: "self"` directive means that the protocol capability is
[provided](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/protocol#provide) by this component.

### Offering

Offering a protocol capability gives a child component access to that
capability:

    {
        offer: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
                from: "self",
                to: [ "#child-a", "#child_b" ],
            },
        ],
    }

## Consuming protocol capabilities

To consume a protocol capability, the component must request the capability and
open the corresponding path in its


[](https://fuchsia.dev/docs/glossary#namespace)


.

To request the capability, add a `use` declaration for it:

    {
        use: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
            },
        ],
    }

This populates the protocol in the component's namespace at the well-known path
`/svc/fuchsia.example.ExampleProtocol`. You can also customize the path:

    {
        use: [
            {
                protocol: "fuchsia.example.ExampleProtocol",
                path: "/my_svc/fuchsia.example.MyExampleProtocol",
            },
        ],
    }

For more information about the open request, see
[life of a protocol open](https://fuchsia.dev/docs/concepts/components/v2/capabilities/life_of_a_protocol_open).

> [!NOTE]
> **Note:** For a working example of routing a protocol capability between components, see [`//examples/components/routing`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/examples/components/routing).

### Consuming optional protocol capabilities

See [Connect Components: Consuming optional capabilities](https://fuchsia.dev/docs/development/components/connect#consuming-optional-capabilities).

## Framework protocols

A *framework protocol* is a protocol provided by the component framework.
Any component may `use` these capabilities by setting `framework` as the source
without an accompanying `offer` from its parent.
Fuchsia supports the following framework protocols:

- [`fuchsia.component.Realm`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component/realm.fidl): Allows a component to manage and bind to its children. Scoped to the component's realm.
- [`fuchsia.component.Binder`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component/binder.fidl): Allows a component to start another component.

    {
        use: [
            {
                protocol: "fuchsia.component.Realm",
                from: "framework",
            },
        ],
    }

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/concepts/components/v2/capabilities/protocol.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/concepts/components/v2/capabilities/protocol.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/concepts/components/v2/capabilities/protocol.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/concepts/components/v2/capabilities/protocol.md "Edit the source code of this page")