forked from modelcontextprotocol/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMcpTransportContext.java
More file actions
59 lines (49 loc) · 1.6 KB
/
McpTransportContext.java
File metadata and controls
59 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright 2024-2025 the original author or authors.
*/
package io.modelcontextprotocol.server;
import java.util.Collections;
/**
* Context associated with the transport layer. It allows to add transport-level metadata
* for use further down the line. Specifically, it can be beneficial to extract HTTP
* request metadata for use in MCP feature implementations.
*
* @author Dariusz Jędrzejczyk
*/
public interface McpTransportContext {
/**
* Key for use in Reactor Context to transport the context to user land.
*/
String KEY = "MCP_TRANSPORT_CONTEXT";
/**
* An empty, unmodifiable context.
*/
@SuppressWarnings("unchecked")
McpTransportContext EMPTY = new DefaultMcpTransportContext(Collections.EMPTY_MAP);
/**
* Extract a value from the context.
* @param key the key under the data is expected
* @return the associated value or {@code null} if missing.
*/
Object get(String key);
/**
* Inserts a value for a given key.
* @param key a String representing the key
* @param value the value to store
*/
void put(String key, Object value);
/**
* Copies the contents of the context to allow further modifications without affecting
* the initial object.
* @return a new instance with the underlying storage copied.
*/
McpTransportContext copy();
/**
* Sends a notification from the server to the client.
* @param method notification method name
* @param params any parameters or {@code null}
*/
default void sendNotification(String method, Object params) {
throw new UnsupportedOperationException("Not supported in this implementation of MCP transport context");
}
}