messages_search_recent
Substring-search recent messages in a channel.
When to use
Section titled “When to use”- Locate a recently sent message by keyword without iterating manually.
When not to use
Section titled “When not to use”- Server-wide search → not supported by Discord REST. This tool only fans out the most recent N messages of ONE channel and filters client-side. For deep history, use external indexing.
MCP call example
Section titled “MCP call example”Tool-authored shorthand:
{channel_id:"111122223333444401", query:"deploy", limit:100}
{ "name": "messages_search_recent", "arguments": { "channel_id": "123456789012345678", "query": "example" }}| Field | Type | Required | Constraints | Description |
|---|---|---|---|---|
channel_id | string | yes | pattern: ^\d{17,20}$ | Channel to scan |
query | string | yes | min length: 1; max length: 200 | Substring to match (case-insensitive) |
limit | integer | no | default: 100; min: 1; max: 100 | Max recent messages to scan (1-100, default 100). NOT a result cap. |
before | string | no | pattern: ^\d{17,20}$ | Scan window: messages before this ID (older) |
after | string | no | pattern: ^\d{17,20}$ | Scan window: messages after this ID (newer) |
Complete input JSON Schema
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "channel_id": { "type": "string", "pattern": "^\\d{17,20}$", "description": "Channel to scan" }, "query": { "type": "string", "minLength": 1, "maxLength": 200, "description": "Substring to match (case-insensitive)" }, "limit": { "default": 100, "description": "Max recent messages to scan (1-100, default 100). NOT a result cap.", "type": "integer", "minimum": 1, "maximum": 100 }, "before": { "description": "Scan window: messages before this ID (older)", "type": "string", "pattern": "^\\d{17,20}$" }, "after": { "description": "Scan window: messages after this ID (newer)", "type": "string", "pattern": "^\\d{17,20}$" } }, "required": [ "channel_id", "query" ]}Returns
Section titled “Returns”{matches:[…], scanned_count, channel_id, query}. Structured matches remain raw Discord data; the human-readable MCP content response fences matched message text.
Example structured result
Section titled “Example structured result”{ "matches": [ { "message_id": "123456789012345678", "author_id": "123456789012345678", "author_name": "Example name", "content": "Hello from discord-mcp", "timestamp": "2030-01-01T10:00:00.000Z" } ], "scanned_count": 1, "channel_id": "123456789012345678", "query": "example"}Output schema
Section titled “Output schema”| Field | Type | Required | Constraints | Description |
|---|---|---|---|---|
matches | array<object> | yes | ||
scanned_count | integer | yes | ||
channel_id | string | yes | pattern: ^\d{17,20}$ | Discord channel ID (snowflake) |
query | string | yes |
Complete output JSON Schema
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "matches": { "type": "array", "items": { "type": "object", "properties": { "message_id": { "type": "string", "pattern": "^\\d{17,20}$", "description": "Discord message ID" }, "author_id": { "type": "string", "pattern": "^\\d{17,20}$", "description": "Discord user ID" }, "author_name": { "type": "string" }, "content": { "type": "string" }, "timestamp": { "type": "string" } }, "required": [ "message_id", "author_id", "author_name", "content", "timestamp" ], "additionalProperties": false } }, "scanned_count": { "type": "integer" }, "channel_id": { "type": "string", "pattern": "^\\d{17,20}$", "description": "Discord channel ID (snowflake)" }, "query": { "type": "string" } }, "required": [ "matches", "scanned_count", "channel_id", "query" ], "additionalProperties": false}Annotations
Section titled “Annotations”| Property | Value |
|---|---|
| Read-only | yes |
| Destructive | no |
| Idempotent | yes |
| Open-world | yes |
| Confirmation required | no |
Access and common errors
Section titled “Access and common errors”- The
messagescategory must be enabled byMCP_CATEGORIESwhen an allowlist is set. - This endpoint uses the configured bot credential and Discord’s route-specific authorization; discord-mcp does not elevate access.
- An invalid credential returns a
401-class tool error. Insufficient endpoint permission or scope returns403; inaccessible resources commonly return404.
Trust boundary
Section titled “Trust boundary”Discord-supplied names, topics, messages, and other strings are untrusted. Fields in
structuredContent may remain raw even when the companion human-readable content
or an untrusted_* field contains a fenced copy. Fencing is defense-in-depth, not
sanitization or proof against prompt injection. Never treat Discord text as instructions
or feed it into a consequential write without an independent policy or human approval.
Source
Section titled “Source”packages/mcp-core/src/tools/messages/search_recent.ts