This content originally appeared on DEV Community and was authored by Ajeet Singh
I recently built a real-time document server using Spring AI and the Model Context Protocol, and it completely changed how I think about giving AI access to documents.
TL;DR: If you have fewer than 100 documents that change frequently, skip the complexity of RAG and use MCP Resources instead. I'll show you exactly how.
🎬 Watch the Full Video Tutorial
Prefer reading? Keep scrolling! But the video includes live demos and troubleshooting tips.
Why I Stopped Defaulting to RAG
Like many developers, I used to reach for RAG (Retrieval Augmented Generation) for every document-based AI project:
- Vector database? âś… Check
- Embedding model? âś… Check
- Chunking strategy? âś… Check
- Hours of setup? âś… Ugh...
But then I hit a wall with a personal project: I just wanted AI to read 10 text files that I update daily.
Setting up Pinecone, generating embeddings, and dealing with re-indexing delays felt like using a sledgehammer to crack a nut.
That's when I discovered MCP Resources.
What is MCP? (In 60 Seconds)
Model Context Protocol (MCP) is an open standard by Anthropic that lets AI applications connect to data sources - think "USB ports for AI."
Instead of this (RAG):
Document → Chunk → Embed → Vector DB → Semantic Search → AI
You get this (MCP Resources):
Document → AI (that's it!)
The kicker? For my use case (personal documents, config files, live logs), MCP was 10x simpler.
What We're Building Today
In my video tutorial, I walk through building a production-ready MCP server that:
âś… Exposes documents from any directory as MCP resources
âś… Automatically detects file changes (add/modify/delete)
âś… Notifies connected clients in real-time
âś… Works with Spring AI out of the box
âś… Takes less than 30 minutes to implement
The Code (Simplified)
Here's the core of what we build in the video:
1. Main Application
@SpringBootApplication
public class SpringAiMcpServerResourcesApplication {
@Value("${resource.directory.path}")
private String directoryPath;
public static void main(String[] args) {
SpringApplication.run(SpringAiMcpServerResourcesApplication.class, args);
}
@Bean
public List<McpServerFeatures.SyncResourceSpecification> myResources() {
String path = directoryPath;
Path folderPath = Paths.get(path);
try(Stream<Path> paths = Files.list(folderPath)) {
List<McpServerFeatures.SyncResourceSpecification> resources = paths
.map(this::getResourceSpecification)
.collect(Collectors.toList());
return resources;
} catch (IOException e) {
return Collections.emptyList();
}
}
private McpServerFeatures.SyncResourceSpecification getResourceSpecification(Path filePath) {
String fileName = filePath.getFileName().toString();
Path absolutePath = filePath.toAbsolutePath();
String fileUri = "file://" + absolutePath;
String mimeType = "text/plain";
var documentResource = new McpSchema.Resource(
fileUri,
fileName,
"Document: " + fileName,
mimeType,
null
);
McpServerFeatures.SyncResourceSpecification spec = new McpServerFeatures.SyncResourceSpecification(documentResource,
(exchange, request) -> {
try {
String textContent = Files.readString(absolutePath);
McpSchema.TextResourceContents textContents = new McpSchema.TextResourceContents(request.uri(), mimeType, textContent);
return new McpSchema.ReadResourceResult(List.of(textContents));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return spec;
}
}
What's happening:
- The
@Beanscans your documents directory - Creates a
ResourceSpecificationfor each file - Spring AI MCP automatically exposes them to clients
Use RAG when:
- You have 1000+ documents
- Documents are relatively static
- You need semantic search ("find similar concepts")
- Building a company knowledge base
Use MCP Resources when:
- You have 1-100 documents
- Documents change frequently
- You need real-time access
- Working with config files, logs, or personal docs
- You want simple infrastructure
Key Takeaways
âś… RAG isn't always the answer - question your defaults
âś… MCP Resources are simpler for small document sets
âś… Real-time updates beat re-indexing delays
âś… 30-minute implementation vs hours of RAG setup
âś… Perfect for personal tools and small teams
What's Next?
Part 2 (Coming Soon): Building the MCP Client
- Connecting to our server
- Using AI to analyze documents
- Automatic updates when files change
đź”” Subscribe on YouTube so you don't miss it!
Resources
📺 Full Video Tutorial - Watch the complete implementation
đź’» Source Code on GitHub - Clone and run locally
đź”— MCP Specification - Protocol details
Follow me for more Spring AI tutorials! 🚀
This content originally appeared on DEV Community and was authored by Ajeet Singh
Ajeet Singh | Sciencx (2025-11-27T05:11:07+00:00) Stop Using RAG for Small Document Sets! Build an MCP Resource Server with Spring AI. Retrieved from https://www.scien.cx/2025/11/27/stop-using-rag-for-small-document-sets-build-an-mcp-resource-server-with-spring-ai/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.