MCP Tools Reference: pubsub.googleapis.com

Tool: publish

Publish a series of one or more messages to an existing topic.

Usage

  1. Create a new byte array to hold the message data.

  2. Populate the byte array with the message data.

  3. Call publish passing the topic name and the byte array.

Important Notes

  • If the publish call returns NOT_FOUND, it likely means the topic does not exist. In this case, you should return an error.

The following sample demonstrate how to use curl to invoke the publish MCP tool.

Curl Request
  
curl  
--location  
 'https://pubsub.googleapis.com/mcp' 
  
 \ 
--header  
 'content-type: application/json' 
  
 \ 
--header  
 'accept: application/json, text/event-stream' 
  
 \ 
--data  
 '{ 
 "method": "tools/call", 
 "params": { 
 "name": "publish", 
 "arguments": { 
 // provide these details according to the tool' 
s  
MCP  
specification  
 } 
  
 } 
,  
 "jsonrpc" 
:  
 "2.0" 
,  
 "id" 
:  
 1 
 } 
 ' 
  

Input Schema

Request for the Publish method.

PublishRequest

JSON representation
 { 
 "projectId" 
 : 
 string 
 , 
 "topicId" 
 : 
 string 
 , 
 "messages" 
 : 
 [ 
 { 
 object (  PubsubMessage 
 
) 
 } 
 ] 
 } 
Fields
projectId

string

Required. The project ID where the topic is located.

topicId

string

Required. The ID of the topic where the messages will be published.

messages[]

object ( PubsubMessage )

Required. The messages to publish.

PubsubMessage

JSON representation
 { 
 "data" 
 : 
 string 
 , 
 "attributes" 
 : 
 { 
 string 
 : 
 string 
 , 
 ... 
 } 
 , 
 "messageId" 
 : 
 string 
 , 
 "publishTime" 
 : 
 string 
 , 
 "orderingKey" 
 : 
 string 
 } 
Fields
data

string ( bytes format)

Optional. The message data field. If this field is empty, the message must contain at least one attribute.

A base64-encoded string.

attributes

map (key: string, value: string)

Optional. Attributes for this message. If this field is empty, the message must contain non-empty data. This can be used to filter messages on the subscription.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" } .

messageId

string

ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the topic. This value may be read by a subscriber that receives a PubsubMessage via a Pull call or a push delivery. It must not be populated by the publisher in a Publish call.

publishTime

string ( Timestamp format)

The time at which the message was published, populated by the server when it receives the Publish call. It must not be populated by the publisher in a Publish call.

Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z" , "2014-10-02T15:01:23.045123456Z" or "2014-10-02T15:01:23+05:30" .

orderingKey

string

Optional. If non-empty, identifies related messages for which publish order should be respected. If a Subscription has enable_message_ordering set to true , messages published with the same non-empty ordering_key value will be delivered to subscribers in the order in which they are received by the Pub/Sub system. All PubsubMessage s published in a given PublishRequest must specify the same ordering_key value. For more information, see ordering messages .

AttributesEntry

JSON representation
 { 
 "key" 
 : 
 string 
 , 
 "value" 
 : 
 string 
 } 
Fields
key

string

value

string

Timestamp

JSON representation
 { 
 "seconds" 
 : 
 string 
 , 
 "nanos" 
 : 
 integer 
 } 
Fields
seconds

string ( int64 format)

Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).

nanos

integer

Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive.

Output Schema

Response for the Publish method.

PublishResponse

JSON representation
 { 
 "messageIds" 
 : 
 [ 
 string 
 ] 
 } 
Fields
messageIds[]

string

Optional. The server-assigned ID of each published message, in the same order as the messages in the request. IDs are guaranteed to be unique within the topic.

Tool Annotations

Destructive Hint: ❌ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ✅

Create a Mobile Website
View Site in Mobile | Classic
Share by: