Skip to content

Commit 1478ba7

Browse files
design: add design for completion (#34)
1 parent abb650e commit 1478ba7

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
@@ -850,7 +850,30 @@ type ClientOptions struct {
850850
851851
### Completion
852852
853-
Clients call the spec method `Complete` to request completions. Servers automatically handle these requests based on their collections of prompts and resources.
853+
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.
854+
855+
```go
856+
// A CompletionHandler handles a call to completion/complete.
857+
type CompletionHandler func(context.Context, *ServerSession, *CompleteParams) (*CompleteResult, error)
858+
859+
type ServerOptions struct {
860+
...
861+
// If non-nil, called when a client sends a completion request.
862+
CompletionHandler CompletionHandler
863+
}
864+
```
865+
866+
#### Securty Considerations
867+
868+
Implementors of the CompletionHandler MUST adhere to the following security guidelines:
869+
870+
- **Validate all completion inputs**: The CompleteRequest received by the handler may contain arbitrary data from the client. Before processing, thoroughly validate all fields.
871+
872+
- **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.
873+
874+
- **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.
875+
876+
- **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.
854877
855878
**Differences from mcp-go**: the client API is similar. mcp-go has not yet defined its server-side behavior.
856879

0 commit comments

Comments
 (0)