types
Concrete resource implementations.
TextResource
Bases: Resource
A resource that reads from a string.
Source code in src/mcp/server/mcpserver/resources/types.py
46 47 48 49 50 51 52 53 | |
read
async
read() -> str
Read the text content.
Source code in src/mcp/server/mcpserver/resources/types.py
51 52 53 | |
BinaryResource
Bases: Resource
A resource that reads from bytes.
Source code in src/mcp/server/mcpserver/resources/types.py
56 57 58 59 60 61 62 63 | |
read
async
read() -> bytes
Read the binary content.
Source code in src/mcp/server/mcpserver/resources/types.py
61 62 63 | |
FunctionResource
Bases: Resource
A resource that defers data loading by wrapping a function.
The function is only called when the resource is read, allowing for lazy loading of potentially expensive data. This is particularly useful when listing resources, as the function won't be called until the resource is actually accessed.
The function can return: - str for text content (default) - bytes for binary content - other types will be converted to JSON
Source code in src/mcp/server/mcpserver/resources/types.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
read
async
Read the resource by calling the wrapped function.
Source code in src/mcp/server/mcpserver/resources/types.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
from_function
classmethod
from_function(
fn: Callable[..., Any],
uri: str,
name: str | None = None,
title: str | None = None,
description: str | None = None,
mime_type: str | None = None,
icons: list[Icon] | None = None,
annotations: Annotations | None = None,
meta: dict[str, Any] | None = None,
) -> FunctionResource
Create a FunctionResource from a function.
Source code in src/mcp/server/mcpserver/resources/types.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
FileResource
Bases: Resource
A resource that reads from a file.
The file is decoded with encoding and served as text, or read as bytes and
served as a base64 blob when encoding is None. When encoding is omitted it
defaults to the charset declared in mime_type, else "utf-8-sig" for
textual mime types (text/*, JSON, XML) and None for everything else; pass
it explicitly to override either way.
Source code in src/mcp/server/mcpserver/resources/types.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
validate_absolute_path
classmethod
Ensure path is absolute.
Source code in src/mcp/server/mcpserver/resources/types.py
161 162 163 164 165 166 167 | |
validate_text_encoding
classmethod
Ensure the encoding names a usable text codec, so a mistake fails at construction not at read.
Source code in src/mcp/server/mcpserver/resources/types.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
read
async
Read the file content.
Source code in src/mcp/server/mcpserver/resources/types.py
184 185 186 187 188 189 190 191 | |
HttpResource
Bases: Resource
A resource that reads from an HTTP endpoint.
Source code in src/mcp/server/mcpserver/resources/types.py
194 195 196 197 198 199 200 201 202 203 204 205 | |
read
async
Read the HTTP content.
Source code in src/mcp/server/mcpserver/resources/types.py
200 201 202 203 204 205 | |
DirectoryResource
Bases: Resource
A resource that lists files in a directory.
Source code in src/mcp/server/mcpserver/resources/types.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
validate_absolute_path
classmethod
Ensure path is absolute.
Source code in src/mcp/server/mcpserver/resources/types.py
216 217 218 219 220 221 222 | |
list_files
List files in the directory.
Source code in src/mcp/server/mcpserver/resources/types.py
224 225 226 227 228 229 230 231 232 233 234 235 236 | |
read
async
read() -> str
Read the directory listing.
Source code in src/mcp/server/mcpserver/resources/types.py
238 239 240 241 242 243 244 245 | |