Skip to content

Commit a7047a0

Browse files
committed
design: add design for completion (modelcontextprotocol#34)
1 parent 88769b3 commit a7047a0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

design/design.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,30 @@ type ClientOptions struct {
879879
880880
### Completion
881881
882-
Clients call the spec method `Complete` to request completions. Servers automatically handle these requests based on their collections of prompts and resources.
882+
Clients call the spec method `Complete` to request completions. If a server installs a `CompletionHandler`, it will be called when the client sends a completion request.
883+
884+
```go
885+
// A CompletionHandler handles a call to completion/complete.
886+
type CompletionHandler func(context.Context, *ServerSession, *CompleteParams) (*CompleteResult, error)
887+
888+
type ServerOptions struct {
889+
...
890+
// If non-nil, called when a client sends a completion request.
891+
CompletionHandler CompletionHandler
892+
}
893+
```
894+
895+
#### Securty Considerations
896+
897+
Implementors of the CompletionHandler MUST adhere to the following security guidelines:
898+
899+
- **Validate all completion inputs**: The CompleteRequest received by the handler may contain arbitrary data from the client. Before processing, thoroughly validate all fields.
900+
901+
- **Implement appropriate rate limiting**: Completion requests can be high-frequency, especially in interactive user experiences. Without rate limiting, a malicious client could potentially overload the server, leading to denial-of-service (DoS) attacks. Consider applying rate limits per client session, IP address, or API key, depending on your deployment model. This can be implemented within the CompletionHandler itself or via middleware (see [Middleware](#middleware)) that wraps the handler.
902+
903+
- **Control access to sensitive suggestions**: Completion suggestions should only expose information that the requesting client is authorized to access. If your completion logic draws from sensitive data sources (e.g., internal file paths, user data, restricted API endpoints), ensure that the CompletionHandler performs proper authorization checks before generating or returning suggestions. This might involve checking the ServerSession context for authentication details or consulting an external authorization system.
904+
905+
- **Prevent completion-based information disclosure**: Be mindful that even seemingly innocuous completion suggestions can inadvertently reveal sensitive information. For example, suggesting internal system paths or confidential identifiers could be an attack vector. Ensure that the generated CompleteResult contains only appropriate and non-sensitive information for the given client and context. Avoid revealing internal data structures or error messages that could aid an attacker.
883906
884907
**Differences from mcp-go**: the client API is similar. mcp-go has not yet defined its server-side behavior.
885908

0 commit comments

Comments
 (0)