Oracle的Jeff Smith和Kris Rice最近写了一篇文章《Introducing MCP Server for Oracle Database》,关于MCP引入到Oracle数据库的场景和操作,有兴趣的朋友,可以阅读一下,数据库和人工智能正在紧密结合。
原文链接:
https://blogs.oracle.com/database/post/introducing-mcp-server-for-oracle-database
Model Context Protocol (MCP) was introduced in November 2024 by Anthropic and was met with viral adoption rates. Until MCP, large language models (LLMs) have never been able to directly interact with external data sources and APIs. Instead, the application layer was responsible for orchestrating context augmentation by using the model to enrich user questions with additional information. MCP’s explosive growth comes from the standardization of a protocol used to add context to an LLM. The absence of such a protocol meant that every tool, every API, and so on, would have to create a bespoke implementation for each platform or integration to offer the same functionality. This often led to duplicated efforts across tools and vendors, requiring developers to write custom code for each LLM provider.
Oracle evaluated MCP and has integrated it into our core developer tools, making the Oracle Database immediately available on any platform supporting MCP. This integration is made available via our modern command line to the Oracle Database, Oracle SQLcl.
Figure 1: MCP Server for Oracle Database
Oracle SQLcl is the command-line interface (CLI) for Oracle Database and is shipped with popular tools such as the Oracle SQL Developer extension for VS Code. It can now be run as an MCP Server and provides MCP tools that allow an AI assistant to securely connect to Oracle Database. SQLcl manages the credentials on the end user’s machine and runs SQL and PL/SQL queries and scripts.
Keeping the world’s most secure database, secure
Granting any LLM access to a database requires maintaining existing security considerations.
A primary concern is unauthorized data exposure, as LLMs process and generate responses based on input data, which could inadvertently allow access to unintended database tables and details.
Oracle Database professionals and administrators should ensure that the database connections utilized by our MCP Server are defined with database users having the least required privileges to accomplish the work at hand. This will limit what is accessible to the LLM.
Oracle recommends taking extreme caution when granting the LLM direct access to production databases; instead, use a sanitized, read-only replica or a dedicated data subset. Regularly audit queries executed by the LLM to detect anomalies or attempts to access restricted data.
Our MCP Server identifies itself to the database via its database sessions using the MODULE and ACTION properties in V$SESSION. Additionally, all interactions and queries executed are logged in a user’s schema via a DBTOOLS$MCP_LOG table.
What is possible with this new platform?
Someone using an AI assistant can now enhance that technology to include interacting with any Oracle Database by simply deploying our MCP Server. The MCP Tools provided to the assistant and their LLMs include making connections to an Oracle Database and running SQL queries and scripts.
For example, let’s say a developer inherits a poorly documented project. They can now use their favorite AI platform to explore their Oracle Database and explain it to them. LLMs are demonstrably adept at understanding and generating SQL. When a person asks for help with database tasks in their native language, LLMs can address these plain language requests by generating SQL.
Now that the Oracle SQLcl MCP server has been made available to LLMs, developers can use AI agentic workflows to directly run generated SQL statements on an Oracle Database and interact with the results. Contrast this with simply having your AI provide SQL for you to manage. Now, we offer developers a workflow where the AI agent can implement its advice directly on the Oracle Database and evaluate the responses.
A sample scenario
“Connect to my fun side project and tell me about what kind of data I have there.”
This is literally a question I’ve submitted to my AI assistant, which just happens to be Anthropic’s Claude-3.7-sonnet model running via the Cline extension in my desktop Cursor application. Note that any editor or assistant that supports MCP can now take advantage of our MCP Server for Oracle Database.
SQLcl’s MCP server has been registered and offers various tools to the LLMs, including one called ‘list-connections.’
Figure 2: list-connections
Connections are defined by using Oracle Database client applications, including SQLcl and the SQL Developer Extension for VS Code. I have created several connections to my personal and work databases. The MCP server has allowed my AI assistant in Cursor to ‘see’ those, including one named ‘Fun Side Project.’
The LLM also wants to run SQL on my behalf to satisfy the second part of my request (i.e., to tell me what kind of data I have there).
Figure 3: run-sql
The LLM has been trained to explore an Oracle Database’s data dictionary by querying the USER_TABLES view and is asking for permission to do so. This query looks reasonable to me, so I click ‘Approve.’
The response comes back to me as a nice paragraph of text, with summarized results, as one would expect from an LLM:
Figure 4: Response from the LLM
And it wants to keep going. Does that STRAVA table really contain the data it appears to?
It prompts me again, this time wanting to run a follow-up query, again using the run-sql tool provided by the Oracle MCP Server:
SELECT column_name,
data_type,
data_length
FROM user_tab_columns
WHERE table_name = ‘STRAVA’ ORDER BY column_id
And again, I approve the request. I recognize what the LLM is after, and I believe this is safe to run on my fun, side project database.
Oracle’s MCP Server (SQLcl) returns a comma-delimited text response showing the columns, data types, and precision/size for each attribute in the STRAVA table, and the LLM inspects this to report back:
Figure 5: Inspection results from LLM
And now it is ready to move onto my next table, NETFLIX.
While I continue to let my AI assistant do its thing, I’m also curious about what this looks like inside the database.
By looking at Oracle’s built-in performance and instrumentation views (V$SESSION), we can see that our MCP Server has identified itself:
USERNAME PROGRAM MODULE ACTION
——– ———- —— ——————-
FUN SQLcl-MCP Claude Claude 3.5 Sonnet
This provides complete transparency into what the LLM is doing in the database, via the MCP Server (SQLcl).
Meanwhile, the LLM has progressed beyond looking at the TABLE definitions and has started querying the first few rows in each table.
The LLM’s findings?
Task Completed
I’ve connected to your “Fun Side Project” database and explored the data you have stored there. This appears to be a personal data tracking project where you’re collecting information from various services and activities in your life. Here’s what I found:
- Fitness Data (STRAVA):
- Running activities with details like date, distance (in meters), and elapsed time (in seconds) – Sample data shows morning and afternoon runs from September 2014
- Entertainment Tracking (NETFLIX):
- Viewing history with details like show titles, viewing times, durations, and device types – Sample data shows you’ve been watching Grey’s Anatomy Season 13 on a Samsung Smart TV
- Music Library (ITUNES):
- Music collection with details like song names, artists, albums, and genres – Includes comprehensive metadata like bit rate, sample rate, play counts, etc. – Sample data shows AC/DC’s “Let There Be Rock – The Movie – Live in Paris” album
- Financial Transactions (BANK_TRANSFERS_1):
- Banking transfers with transaction IDs, source/destination accounts, and amounts – Simple structure focused on transfer information
- Water Usage (WATER):
- Table is set up to track water consumption with service provider, reading date, and usage in gallons – Currently contains no data
This database gives you a comprehensive view of various aspects of your life – from fitness and entertainment to consumption habits and finances – all in one centralized location.
Let’s keep exploring my database
Since the LLM now ‘knows’ about my NETFLIX collection, let’s see if it can tell me what I’ve wasted time watching over the years.
“What are the most watched shows from my NETFLIX collection?”
The LLM immediately recognizes that it needs to query this table, and asks for approval to run this via the Oracle MCP run-sql tool:
SELECT regexp_substr(title, ‘^[^:]+’) AS show_name,
COUNT() AS view_count FROM netflix GROUP BY regexp_substr(title, ‘^[^:]+’) ORDER BY COUNT() DESC
And from the hundreds of SQL results that came back, the LLM again helpfully summarizes my list:
Figure 6: Summarized results
And yes, “We Bare Bears” is a Cartoon Network show for kids.
Only scratching the surface
This has only been the most basic demonstration of what’s possible with our new MCP Server for the Oracle Database. Your favorite development environments and AI code assistants now have access to your Oracle Database to work on your behalf.
The requirements are simple:
- an Oracle Database to work with
- Oracle SQLcl with one or more defined database connections
- your preferred IDE and LLM
SQLcl is capable of much more than simply running queries. Over the past decade, Oracle has been adding useful features for data professionals, developers, and DBAs, including support for importing and exporting data (Data Pump), managing high availability functions such as database switchover events (Data Guard), performing performance diagnostics (AWR), and much, much more.
We will be releasing monthly SQLcl MCP Server updates, along with additional tools that your LLMs can utilize to work more efficiently with the database. This means the LLM doesn’t need to generate SQL to see if the database is performing well; it can simply use the provided performance tool from the SQLcl MCP server.
Getting started
The easiest way to get started with our SQLcl MCP server is via VS Code. Our SQL Developer Extension for VS Code ships with SQLcl, and upon activation, it automatically registers its MCP server with VS Code for use with Microsoft Copilot.
Figure 7: Simply search for ‘SQL Developer’ in the VS Code Marketplace
You can observe the additional tools available to Copilot under the SQLcl MCP Server section.
Figure 8: Additional tools available
Creating connections using the SQL Developer Extension should be straightforward for any Oracle Database user. Simply supply the username, password, and database properties such as server name, port, and database service name.
If you need an Oracle Database to get started, our 23ai Free edition is available for free to anyone for any purpose.
Configuring the SQLcl MCP Server for your other environments and tools is demonstrated in our documentation.
This isn’t just for developers!
The rapid advancement of AI is transforming the way people live and work across the globe. AI-powered systems now make it much easier to get help with questions and tasks, lowering barriers of entry to many technology platforms. This evolution has now extended to the Oracle Database, which is trusted to store some of the world’s most critical data and run mission-critical services and applications.
Business users who need timely answers to questions not covered by existing reports or dashboards can now simply ask the database using an AI interface. The SQLcl MCP Server offers a secure and user-friendly way to connect AI capabilities with the Oracle Database, seamlessly bringing together two powerful technologies.
声明:来自bisal的个人杂货铺,仅代表创作者观点。链接:https://eyangzhen.com/1955.html