PostgreSQL için Agentic AI
Bugün en çok merak ettiğim konulardan biriyle ilgili bir çalışma yapacağız. İnanın ben de çok heyecanlıyım. Çalışmam başarılı olacak mı? Olmayacak mı? PostgreSQL içinde Agentic AI çalışması yapma hayalim var. MCP/Agentic AI konusunda çok fazla doküman okudum. Ama şimdi dokümanda yazanları tecrübe etme zamanı.
Öncelikle, Oracle Cloud üzerinde Ubuntu (Ubuntu 24.04 LTS) sistem kurdum, sistemi güncelledim ve “reboot” ettim.
**
Kurduğum Ubuntu işletim sistemi özelliklerini aşağıdaki komutla görebiliriz. Sunucu saat dilimi UTC olduğu için zaman damgaları +00 görünmektedir.
ubuntu@postgresql-mcp-poc:~$ uname -a
Linux postgresql-mcp-poc 6.14.0-1016-oracle #16~24.04.1-Ubuntu SMP Mon Oct 20 21:11:02 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@postgresql-mcp-poc:~$
**
Sistemi güncelledim ve yeniden başlattım (reboot).
**
ubuntu@postgresql-mcp-poc:~$ sudo apt update
Hit:1 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://security.ubuntu.com/ubuntu noble-security InRelease
Get:3 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Hit:4 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble-backports InRelease
Fetched 126 kB in 0s (378 kB/s)
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
64 packages can be upgraded. Run ‘apt list –upgradable’ to see them.
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ sudo apt upgrade -y
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Calculating upgrade… Done
The following NEW packages will be installed:
… (Basitlik açısından komutun çıktısını kestim.)
ubuntu@postgresql-mcp-poc:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble InRelease
Hit:3 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:4 http://eu-frankfurt-1-ad-2.clouds.archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
All packages are up to date.
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ sudo reboot
Broadcast message from root@postgresql-mcp-poc on pts/1 (Sat 2025-12-27 16:08:21 UTC):
The system will reboot now!
ubuntu@postgresql-mcp-poc:~$
**
Aşağıdaki komutla PostgreSQL ve ek araçları (contrib) kurdum. Kurulum sırasında PostgreSQL 16 paketi ve gerekli istemci bileşenleri otomatik olarak indirildi ve 16/main isimli varsayılan cluster oluşturuldu.
ubuntu@postgresql-mcp-poc:~$ sudo apt install -y postgresql postgresql-contrib
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
The following additional packages will be installed:
Setting up postgresql-contrib (16+257build1.1) …
Setting up postgresql (16+257build1.1) …
… (Basitlik açısından komutun çıktısını kestim.)
ubuntu@postgresql-mcp-poc:~$
Ubuntu’da postgresql.service “umbrella” servisi gibi çalışmaktadır. Asıl çalışan servis cluster servisidir. postgresql@16-main servisinin active (running) görülmesi PostgreSQL cluster’ının çalıştığını gösterir.
ubuntu@postgresql-mcp-poc:~$ sudo systemctl status postgresql –no-pager
● postgresql.service – PostgreSQL RDBMS
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
Active: active (exited) since Sat 2025-12-27 16:13:28 UTC; 2min 39s ago
Main PID: 2980 (code=exited, status=0/SUCCESS)
CPU: 1ms
Dec 27 16:13:28 postgresql-mcp-poc systemd[1]: Starting postgresql.service – PostgreSQL RDBMS…
Dec 27 16:13:28 postgresql-mcp-poc systemd[1]: Finished postgresql.service – PostgreSQL RDBMS.
ubuntu@postgresql-mcp-poc:~$ sudo systemctl status postgresql@16-main –no-pager
● postgresql@16-main.service – PostgreSQL Cluster 16-main
Loaded: loaded (/usr/lib/systemd/system/postgresql@.service; enabled-runtime; preset: enabled)
Active: active (running) since Sat 2025-12-27 16:13:32 UTC; 4min 9s ago
Process: 3852 ExecStart=/usr/bin/pg_ctlcluster –skip-systemctl-redirect 16-main start (code=exited, status=0/SUCCESS)
Main PID: 3857 (postgres)
Tasks: 6 (limit: 14237)
Memory: 19.7M (peak: 27.4M)
CPU: 173ms
CGroup: /system.slice/system-postgresql.slice/postgresql@16-main.service
├─3857 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -c config_file=/etc/postgresql/16/main/postgresql.conf
├─3858 “postgres: 16/main: checkpointer ”
├─3859 “postgres: 16/main: background writer ”
├─3861 “postgres: 16/main: walwriter ”
├─3862 “postgres: 16/main: autovacuum launcher ”
└─3863 “postgres: 16/main: logical replication launcher ”
Dec 27 16:13:30 postgresql-mcp-poc systemd[1]: Starting postgresql@16-main.service – PostgreSQL Cluster 16-main…
Dec 27 16:13:32 postgresql-mcp-poc systemd[1]: Started postgresql@16-main.service – PostgreSQL Cluster 16-main.
Kurulumun doğru yapıldığını doğrulamak için PostgreSQL sürümünü sorguladım. PostgreSQL 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1) çıktısını aşağıda görüyoruz.
ubuntu@postgresql-mcp-poc:~$ sudo -u postgres psql -c “SELECT version();”
version
—————————————————————————————————————————————-
PostgreSQL 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit
(1 row)
ubuntu@postgresql-mcp-poc:~$
**
Agentic AI/MCP tarafına geçmeden önce PostgreSQL içinde “agent” (Node.js orkestratörü) için izole bir alan yaratacağım. Ayrı bir veri tabanı ve ayrı bir kullanıcı oluşturacağım.
**
ubuntu@postgresql-mcp-poc:~$ sudo -u postgres psql
psql (16.11 (Ubuntu 16.11-0ubuntu0.24.04.1))
Type “help” for help.
postgres=# CREATE DATABASE mcp_lab;
CREATE USER mcp_user WITH PASSWORD ‘CHANGE_ME_STRONG’;
ALTER DATABASE mcp_lab OWNER TO mcp_user;
GRANT ALL PRIVILEGES ON DATABASE mcp_lab TO mcp_user;
\q
CREATE DATABASE
CREATE ROLE
ALTER DATABASE
GRANT
ubuntu@postgresql-mcp-poc:~$
Aşağıda veri tabanına bağlantı testimizi de yaptım.
ubuntu@postgresql-mcp-poc:~$ psql “host=127.0.0.1 dbname=mcp_lab user=mcp_user password=CHANGE_ME_STRONG” \
-c “SELECT current_user, current_database(), now();”
current_user | current_database | now
————–+——————+——————————-
mcp_user | mcp_lab | 2025-12-27 16:41:05.530631+00
(1 row)
ubuntu@postgresql-mcp-poc:~$
**
PostgreSQL’de gerekli tanımlamaları yaptım. Müşteri bilgilerini temsil eden customers tablosunu ve sipariş verilerini temsil eden orders tablosunu oluşturdum. Tablolar arasında yabancı anahtar ilişkisi kurarak, farklı iş senaryolarını yansıtan örnek veriler ekledim. Bu çalışmada sorgu üretimini dinamik yapmadım. Güvenli bir SQL şablonunu sabitledim. Agentic tarafı ‘tool çağırma + sonuç gözlemleme + LLM ile yorumlama’ olarak gösterdim. Yani, bu çalışma tam plan -> refine döngüsü değil (LLM ile araç seçimi/SQL üretimi yok), daha ziyade execute -> observe + sonuç yorumlama gösterimidir. Bu çalışmada agent (Node.js orkestratörü), önceden tanımlı güvenli sorgu kalıbını MCP üzerinden çalıştıracak şekilde kurgulandı.
**
ubuntu@postgresql-mcp-poc:~$ psql “host=127.0.0.1 dbname=mcp_lab user=mcp_user password=CHANGE_ME_STRONG” <<‘SQL’ CREATE TABLE customers ( customer_id SERIAL PRIMARY KEY, full_name TEXT NOT NULL, segment TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT now() ); CREATE TABLE orders ( order_id SERIAL PRIMARY KEY, customer_id INT NOT NULL REFERENCES customers(customer_id), order_total NUMERIC(12,2) NOT NULL, status TEXT NOT NULL, ordered_at TIMESTAMP NOT NULL DEFAULT now() ); INSERT INTO customers (full_name, segment) VALUES (‘Sarav Asiye Yigit’,’SMB’), (‘Zohre Hacer’,’ENT’), (‘Dursun Ali’,’SMB’); INSERT INTO orders (customer_id, order_total, status) VALUES (1,1250.00,’PAID’), (1,300.00,’REFUNDED’), (2,9900.00,’PAID’), (3,450.00,’PENDING’); SQL CREATE TABLE CREATE TABLE INSERT 0 3 INSERT 0 4 ubuntu@postgresql-mcp-poc:~$ ubuntu@postgresql-mcp-poc:~$ psql “host=127.0.0.1 dbname=mcp_lab user=mcp_user password=CHANGE_ME_STRONG” \ -c “SELECT customer_id, full_name, segment FROM customers;” customer_id | full_name | segment ————-+——————-+——— 1 | Sarav Asiye Yigit | SMB 2 | Zohre Hacer | ENT 3 | Dursun Ali | SMB (3 rows) ubuntu@postgresql-mcp-poc:~$ ** Şimdiye kadar, PostgreSQL 16’yı çalıştırdım. Agent (Node.js orkestratörü) için izole veri tabanı, mcp_lab oluşturdum. Anlamlı bir veri modeli oluşturdum: customers, orders. Örnek veriler tanımladım. Localhost üzerinden güvenli erişim sağladım. MCP Server’ımızı yazmamız gerekiyor. Basit bir MCP Server yazacağız. Bu amaç ile ubuntu sunucumuza Node.js 20 LTS kuralım. ** Komutu aşağıda görebiliriz. Çıktısını basitlik açısından kestim. ubuntu@postgresql-mcp-poc:~$ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash – sudo apt install -y nodejs node -v npm -v 2025-12-27 17:15:08 – Installing pre-requisites No VM guests are running outdated hypervisor (qemu) binaries on this host. … (Basitlik açısından komutun çıktısını kestim.) v20.19.6 10.8.2 ubuntu@postgresql-mcp-poc:~$ Node.js kurulumunu tamamlamış oldum. ** MCP Server projesini oluşturdum. MCP Server kodu için ChatGPT’den destek aldım. ** Komut çıktısı aşağıdadır. ubuntu@postgresql-mcp-poc:~$ mkdir -p ~/mcp-pg-server && cd ~/mcp-pg-server npm init -y npm i @modelcontextprotocol/sdk pg Wrote to /home/ubuntu/mcp-pg-server/package.json: { “name”: “mcp-pg-server”, “version”: “1.0.0”, “main”: “index.js”, “scripts”: { “test”: “echo \”Error: no test specified\” && exit 1″ }, “keywords”: [], “author”: “”, “license”: “ISC”, “description”: “” } added 104 packages, and audited 105 packages in 5s 27 packages are looking for funding run `npm fund` for details found 0 vulnerabilities ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ pwd /home/ubuntu/mcp-pg-server ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ls -ltr total 56 -rw-rw-r– 1 ubuntu ubuntu 316 Dec 27 17:20 package.json -rw-rw-r– 1 ubuntu ubuntu 45072 Dec 27 17:20 package-lock.json drwxrwxr-x 107 ubuntu ubuntu 4096 Dec 27 17:20 node_modules ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ nano server.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ls -ltr total 60 -rw-rw-r– 1 ubuntu ubuntu 316 Dec 27 17:20 package.json -rw-rw-r– 1 ubuntu ubuntu 45072 Dec 27 17:20 package-lock.json drwxrwxr-x 107 ubuntu ubuntu 4096 Dec 27 17:20 node_modules -rw-rw-r– 1 ubuntu ubuntu 2445 Dec 27 17:24 server.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ Şimdi ise Client.mjs dosyası oluşturdum. Client.mjs örnek bir istemcidir. ubuntu@postgresql-mcp-poc:~$ cd ~/mcp-pg-server ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ pwd /home/ubuntu/mcp-pg-server ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ls -ltr total 60 -rw-rw-r– 1 ubuntu ubuntu 316 Dec 27 17:20 package.json -rw-rw-r– 1 ubuntu ubuntu 45072 Dec 27 17:20 package-lock.json drwxrwxr-x 107 ubuntu ubuntu 4096 Dec 27 17:20 node_modules -rw-rw-r– 1 ubuntu ubuntu 2803 Dec 27 17:31 server.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ nano client.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ client.mjs için de ChatGPT’den destek aldım. PG_URL’i export ettim. ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ export PG_URL=”postgresql://mcp_user:CHANGE_ME_STRONG@127.0.0.1:5432/mcp_lab” ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ echo $PG_URL postgresql://mcp_user:CHANGE_ME_STRONG@127.0.0.1:5432/mcp_lab ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ PG_URL’in kalıcılığını sağladım. ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ echo ‘export PG_URL=”postgresql://mcp_user:CHANGE_ME_STRONG@127.0.0.1:5432/mcp_lab”‘ >> ~/.bashrc
source ~/.bashrc
ubuntu@postgresql-mcp-poc:~/mcp-pg-server$
client.mjs’i çalıştırdım.
ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ node client.mjs
mcp-pg-readonly MCP Server running on stdio
Tools: [ ‘list_tables’, ‘query’ ]
list_tables:
[
{
type: ‘text’,
text: ‘[\n’ +
‘ {\n’ +
‘ “table_name”: “customers”\n’ +
‘ },\n’ +
‘ {\n’ +
‘ “table_name”: “orders”\n’ +
‘ }\n’ +
‘]’
}
]
query(customers):
[
{
type: ‘text’,
text: ‘[\n’ +
‘ {\n’ +
‘ “customer_id”: 1,\n’ +
‘ “full_name”: “Sarav Asiye Yigit”,\n’ +
‘ “segment”: “SMB”\n’ +
‘ },\n’ +
‘ {\n’ +
‘ “customer_id”: 2,\n’ +
‘ “full_name”: “Zohre Hacer”,\n’ +
‘ “segment”: “ENT”\n’ +
‘ },\n’ +
‘ {\n’ +
‘ “customer_id”: 3,\n’ +
‘ “full_name”: “Dursun Ali”,\n’ +
‘ “segment”: “SMB”\n’ +
‘ }\n’ +
‘]’
}
]
ubuntu@postgresql-mcp-poc:~/mcp-pg-server$
Bu komut çıktısı ile list_tables aracının customers ve orders tablolarını döndürdüğünü doğruladım. Ayrıca query aracı ile customers tablosundan verilerin başarıyla çekildiğini gördüm. Yukarıdaki komut (MCP Server)’ın kurulduğunu ve çalıştığını doğruluyor.
**
client.mjs çalıştırıldığında, MCP Server stdio transport üzerinden otomatik olarak bir subprocess olarak çalışmaktadır. MCP Server’i, PostgreSQL ile doğrudan bağlantı kuran tek bileşen olarak konumlandırdım. Ek olarak, yalnızca SELECT / WITH (CTE) sorgularına izin verecek şekilde; temel DDL/DML ifadelerini reddeden bir read-only kontrol ekledim.
Bu çalışmada, MCP, araç (tool) arayüzünü standartlaştırdı. Kontrol/güvenlik sınırını ise MCP Server’a eklediğim read-only kısıtları sağladı. MCP mimarisi bu çalışma kapsamında iki temel bileşenden oluşmaktadır: MCP Server ve MCP Client. Bu iki bileşen arasındaki net ayrım, güvenlik sınırlarının korunması ve sistem davranışlarının kontrol altında tutulması açısından kritik bir rol oynamaktadır.
MCP Server, PostgreSQL gibi kritik bir veri kaynağını izole eden bir “ara kontrol katmanı” (tool layer) görevi görmektedir. Veri tabanı bağlantı bilgileri, kullanıcı adları ve yetkiler MCP Server içinde tutulmaktadır. Bu çalışmada PostgreSQL bağlantı bilgileri LLM’e aktarılmadı. Bağlantı bilgisi yalnızca uygulama çalışma zamanı katmanında (MCP Server subprocess’i ve onu başlatan local orkestrasyon) tutuldu. MCP Server üzerinde tanımlanan list_tables ve query araçları, veri tabanına erişimin sınırlarını açıkça belirlemekte ve yalnızca güvenli kabul edilen read-only sorguların çalıştırılmasına izin vermektedir. Böylece MCP Server, PostgreSQL ile üst katmanlar arasında pratik bir güvenlik bariyeri oluşturmaktadır.
MCP Client ise MCP Server ile etkileşime giren ve bu araçları çağıran yürütme katmanı olarak konumlanmıştır. MCP Client’ın temel sorumluluğu, MCP Server’ı stdio üzerinden subprocess olarak başlatmak, sunulan araçları keşfetmek ve bu araçları programatik olarak çağırmaktır. Bu mimaride MCP Client, veri tabanı sorgularını kendisi çalıştırmaz; yalnızca MCP Server tarafından sunulan araçlar üzerinden dolaylı erişim sağlar. MCP Server’ın stdio üzerinden çalıştırılması sayesinde ek bir ağ portu açılmasına gerek kalmaz, ağ erişimi ortadan kaldırılır ve saldırı yüzeyi minimumda tutulur.
LLM’i bu sürümde planlayıcı olarak kullanmadım; sadece sonuç özetleme/yorumlama için kullandım. MCP Server’ın çalıştırdığı sorgudan dönen sonuçları LLM’e verdim. Başka bir ifadeyle, LLM sorgu çalıştırmaz ve veri tabanına erişmez, yalnızca elde edilen sonuçlar üzerinden özetleme, açıklama ve işsel çıkarım üretme görevini üstlenir. Aslında başlangıçta planım, LLM, PostgreSQL’e sorgu yazan ya da MCP tool çağıran taraf olsun şeklindeydi. Ama beni saatlerce uğraştırdı. Format/parse problemleri yaşadım. Bu yüzden çalışmayı stabil tutmak adına sorguyu agent (Node.js orkestratörü) tarafında sabitlemeye karar verdim.
Bu net görev ayrımı sayesinde PostgreSQL yalnızca veriyi tutan pasif bir katman olarak kalırken, MCP Server güvenliği ve erişim kontrolünü sağladı, MCP Client yürütmeyi ve orkestrasyonu üstlendi. Oracle Generative AI ise teknik sonuçlara anlam kazandıran yorumlayıcı olarak konumladım. LLM’in görevini aldığım hatalardan ötürü en aza indirgemiş olsamda, bu yapı, agentic AI senaryolarının kurumsal veri tabanlarıyla kontrollü, denetlenebilir ve üretim ortamlarına uygun bir şekilde entegre edilebileceğini pratik olarak yine de gösteriyor diye düşünüyorum.
**
sftp ile OCI Pem dosyasını yükledim. Gerekli dizin oluşturma ve kopyalama çalışmalarını yaptım.
ubuntu@postgresql-mcp-poc:~$ pwd
/home/ubuntu
ubuntu@postgresql-mcp-poc:~$ ls -ltra
total 60
-rw-r–r– 1 ubuntu ubuntu 807 Mar 31 2024 .profile
-rw-r–r– 1 ubuntu ubuntu 220 Mar 31 2024 .bash_logout
… (Basitlik açısından komutun çıktısını kestim.)
drwxrwxr-x 3 ubuntu ubuntu 4096 Dec 27 17:51 mcp-pg-server
-drwxr-x— 7 ubuntu ubuntu 4096 Dec 28 08:58 .
-rw-rw-r– 1 ubuntu ubuntu 1715 Dec 28 08:58 asiye.yigit@xyzxyzxyz.pem
ubuntu@postgresql-mcp-poc:~$ mkdir -p ~/.oci
chmod 700 ~/.oci
ubuntu@postgresql-mcp-poc:~$ ls -ld ~/.oci
drwx—— 2 ubuntu ubuntu 40
ubuntu@postgresql-mcp-poc:~$ mv ~/asiye.yigit@xyzxyzxyz.pem ~/.oci/oci_api_key.pem
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ chmod 600 ~/.oci/oci_api_key.pem
ubuntu@postgresql-mcp-poc:~$ ls -lah ~/.oci
total 12K
drwx—— 2 ubuntu ubuntu 4.0K Dec 28 09:00 .
drwxr-x— 8 ubuntu ubuntu 4.0K Dec 28 09:00 ..
-rw——- 1 ubuntu ubuntu 1.7K Dec 28 08:58 oci_api_key.pem
ubuntu@postgresql-mcp-poc:~$
Python3 için pip komutunu kurdum.
ubuntu@postgresql-mcp-poc:~$ sudo apt update
sudo apt install -y python3-pip
All packages are up to date.
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
The following additional packages will be installed:
… (Basitlik açısından komutun çıktısını kestim.)
ubuntu@postgresql-mcp-poc:~$
pipx’i kurdum ve Python araçlarını izole ortamda çalıştırabilmek için PATH ayarlarını otomatik olarak yapılandırdım.
ubuntu@postgresql-mcp-poc:~/.oci$ sudo apt install -y pipx
pipx ensurepath
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
… (Basitlik açısından komutun çıktısını kestim.)
You will need to open a new terminal or re-login for the PATH changes to take effect.
Otherwise pipx is ready to go! ✨ ✨
ubuntu@postgresql-mcp-poc:~/.oci$
OCI ile ilgili gerekli tanımlamaları yaptım.
ubuntu@postgresql-mcp-poc:~$ pipx install oci-cli
installed package oci-cli 3.71.4, installed using Python 3.12.3
These apps are now globally available
– create_backup_from_onprem
– oci
done! ✨ ✨
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ oci –version
3.71.4
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ which oci
/home/ubuntu/.local/bin/oci
ubuntu@postgresql-mcp-poc:~$
ubuntu@postgresql-mcp-poc:~$ chmod 600 ~/.oci/config ~/.oci/oci_api_key.pem
ls -lah ~/.oci
total 16K
drwx—— 2 ubuntu ubuntu 4.0K Dec 28 09:25 .
drwxr-x— 8 ubuntu ubuntu 4.0K Dec 28 09:00 ..
-rw——- 1 ubuntu ubuntu 305 Dec 28 09:25 config
-rw——- 1 ubuntu ubuntu 1.7K Dec 28 08:58 oci_api_key.pem
ubuntu@postgresql-mcp-poc:~$
OCI’ye gerçekten bağlandığımı doğruladım.
ubuntu@postgresql-mcp-poc:~$ oci os ns get
{
“data”: “fr65zqa002oq”
}
ubuntu@postgresql-mcp-poc:~$
OCI CLI’nin çalıştığını doğrulayıp, hesabımın Object Storage namespace’ini ve abone olduğu region’ları sorguladım.
ubuntu@postgresql-mcp-poc:~$ oci –version
oci os ns get
oci iam region-subscription list
3.71.4
{
“data”: “fr65zqa002oq”
}
{
“data”: [
{
“is-home-region”: true,
“region-key”: “FRA”,
“region-name”: “eu-frankfurt-1”,
“status”: “READY”
}
]
}
ubuntu@postgresql-mcp-poc:~$
COMPARTMENT_ID’mi export ettim. Güvenlik nedeniyle bilinçli olarak ID’mi aşağıdaki komutlarda değiştirdim.
ubuntu@postgresql-mcp-poc:~$ export COMPARTMENT_ID=”ocid1.xxxxxxx”
echo $COMPARTMENT_ID
ocid1.xxxxxxx
ubuntu@postgresql-mcp-poc:~$
OCI’da olan modelleri listeledim. Çok uzun bir liste çıkıyor. Bilinçli olarak çıktıyı kestim. Biz, cohere.command-r-plus-08-2024 modelini kullanacağız.
ubuntu@postgresql-mcp-poc:~$ oci generative-ai model-collection list-models –compartment-id “$COMPARTMENT_ID”
{
“data”: {
“items”: [
{
“base-model-id”: null,
“capabilities”: [
“CHAT”
],
],
“compartment-id”: null,
“defined-tags”: {},
“display-name”: “cohere.command-r-plus-08-2024”,
“fine-tune-details”: null,
“freeform-tags”: {},
}
ubuntu@postgresql-mcp-poc:~$
Home dizinine geçip OCI Generative AI inference ile bir chat isteğinin varsayılan servis modunu JSON çıktısı olarak alıp dosyaya kaydettim ve içeriğini görüntüledim.
ubuntu@postgresql-mcp-poc:~$ cd ~
oci generative-ai-inference chat-result chat-cohere-chat-request \
–generate-param-json-input serving-mode > serving-mode.json
cat serving-mode.json
[
“This parameter should actually be a JSON object rather than an array – pick one of the following object variants to use”,
{
“endpointId”: “string”,
“servingType”: “DEDICATED”
},
{
“modelId”: “string”,
“servingType”: “ON_DEMAND”
}
]
ubuntu@postgresql-mcp-poc:~$
serving-mode.json dosyasına doğru modeli konumlandırdım. Modelin ismini, ortamıma ilişkin meta data içerdiğinden bilinçli olarak aşağıda değiştirdim.
ubuntu@postgresql-mcp-poc:~$ cat > ~/serving-mode.json <<‘JSON’ { “modelId”: “ocid1.generativeaimodel.oc1.eu-frankfurt-xxxxx”, “servingType”: “ON_DEMAND” } JSON cat ~/serving-mode.json { “modelId”: “ocid1.generativeaimodel.oc1.eu-frankfurt-xxxxx”, “servingType”: “ON_DEMAND” } ubuntu@postgresql-mcp-poc:~$ Aşağıda yine COMPARTMENT_ID’yi güvenlik nedeniyle bilinçli olarak değiştirdim. OCI Generative AI Inference üzerinden belirttiğim compartment ve serving-mode ile Cohere tabanlı modele bir chat prompt gönderip yanıtını başarıyla aldım. ubuntu@postgresql-mcp-poc:~$ export COMPARTMENT_ID=”ocid1.xxxxxxx” oci generative-ai-inference chat-result chat-cohere-chat-request \ –chat-request-message “Introduce yourself in one short sentence.” \ –compartment-id “$COMPARTMENT_ID” \ –serving-mode file://serving-mode.json { “data”: { “chat-response”: { “api-format”: “COHERE”, “chat-history”: [ { “message”: “Introduce yourself in one short sentence.”, “role”: “USER” }, { “message”: “I am Command, an AI assistant chatbot designed to help you with your queries and tasks.”, “role”: “CHATBOT”, “tool-calls”: null } ], “citations”: null, “documents”: null, “error-message”: null, “finish-reason”: “COMPLETE”, “is-search-required”: null, “prompt”: null, “search-queries”: null, “text”: “I am Command, an AI assistant chatbot designed to help you with your queries and tasks.”, “tool-calls”: null, “usage”: { “completion-tokens”: 18, “completion-tokens-details”: null, “prompt-tokens”: 8, “prompt-tokens-details”: null, “total-tokens”: 26 } }, “model-id”: “ocid1.generativeaimodel.oc1.eu-frankfurt-xxxxx”, “model-version”: “1.6” } } ubuntu@postgresql-mcp-poc:~$ ** Şimdiye kadar PostgreSQL üzerinde anlamlı bir veri modeli kurdum (customers / orders) ve MCP Server’ı (server.mjs) PostgreSQL’e bağlanan tek katman olacak şekilde konumlandırdım. Ayrıca yalnızca SELECT / WITH (CTE) sorgularına izin veren ve temel DDL/DML ifadelerini reddeden bir read-only kontrol ekledim. Bununla birlikte, OCI CLI üzerinden Oracle Generative AI (Cohere Command R+ 08-2024) modeline prompt gönderip yanıt alabildiğimi doğruladım. Sonrasında “agentic” akışı göstermek için agent.mjs ile iki dünyayı birleştirdim. agent.mjs içinde MCP Client fonksiyonunu kullanan bir orkestrasyon katmanı var. Bu çalışmada agent.mjs şu rolü üstleniyor: kullanıcı iş sorusunu alıyor, MCP Client rolüyle MCP Server’ı stdio üzerinden subprocess olarak başlatıyor, ardından MCP Server üzerindeki query aracını çağırarak PostgreSQL’den sonucu çekiyor. Yani bu aşamada “execute” ve “observe” kısmını gerçek sistemler üzerinde yapıyoruz: sorgu çalışıyor ve çıktıyı görüyoruz. Bu akışa LLM ile yorumlama (interpret) adımını da ekledim. LLM, PostgreSQL’e sorgu yazan ya da MCP tool çağıran taraf değil. (Yukarıda da bahsettiğim gibi bunu denemeye çalıştığımda format/parse problemleri yaşadım. Çalışmayı devam ettirmek adına sorguyu güvenli şekilde agent (Node.js orkestratörü) tarafında sabitledim.) Buna karşılık LLM’i yine sürece dahil ettim. PostgreSQL’den MCP üzerinden dönen sonuçları Oracle Generative AI modeline verip, modelin bu teknik çıktıyı “LLM Interpretation” bölümünde özetlemesini ve işsel bir yorum/öneri üretmesini sağladım. Böylece LLM doğrudan veri tabanına bağlanmadan, yalnızca güvenli katmanın ürettiği çıktıyı anlamlandıran bir bileşen olarak çalışmış oldu. OCI_COMPARTMENT_ID, OCI_MODEL_ID ve OCI_REGION değişkenlerimizi tanımladım ve ~/.bashrc’de kalıcılığını sağladım. Güvenlikten ötürü bu adımlarımı buraya yapıştırmadım. Ama kullandığımız komutlar belli zaten, export ve source komutları. llm_cli_test.mjs script’ini ChatGPT ile oluşturduk. Amacım süreci netleştirmekti. Sonrasında geniş zamanımızda bu içerikleri kendimizde elbette yazabiliriz. Şimdi ise, agent.mjs dosyasını oluşturdum. Yine ChatGPT’den destek aldım. ** ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ cd ~/mcp-pg-server nano agent.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ls -ld ~/mcp-pg-server/agent.mjs -rw-rw-r– 1 ubuntu ubuntu 4536 Dec 28 17:16 /home/ubuntu/mcp-pg-server/agent.mjs ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ** agent.mjs dosyasının içeriğini eklemedim. Çok uzun bir dosya çünkü. Önemli olan benim için şu an süreci anlamak ve işletmektir. Nihayet uzun uğraşlar sonucunda aşağıda olan çıktıyı alabildim. ** ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ node agent.mjs mcp-pg-readonly MCP Server running on stdio MCP Tools: [ ‘list_tables’, ‘query’ ] User question: Which customers have the highest total “PAID” order amount? Return names and totals. Using SQL: SELECT full_name, SUM(order_total) AS total_paid FROM customers JOIN orders ON customers.customer_id = orders.customer_id WHERE status = ‘PAID’ GROUP BY full_name ORDER BY total_paid DESC Customers by total “PAID” amount: 1. Zohre Hacer: 9900.00 2. Sarav Asiye Yigit: 1250.00 LLM Interpretation: **Summary:** The top-paying customers are Zohre Hacer and Sarav Asiye Yigit, with a significant difference in their total paid amounts. – Zohre Hacer is the highest-paying customer, with a total of $9900. – Sarav Asiye Yigit’s total paid amount is considerably lower at $1250. **Next Step:** Consider reaching out to these customers with personalized offers to show appreciation and encourage further purchases. ubuntu@postgresql-mcp-poc:~/mcp-pg-server$ ** Bu çalışmada, PostgreSQL yalnızca veriyi tutan pasif katmandır. MCP Server (server.mjs) PostgreSQL’e bağlanan ve SQL’i gerçekten çalıştıran katmandır. Bu çalışmada read-only kontrol temel düzeydedir. Üretimde allowlist, çoklu-statement engeli, timeout/limit ve denetim log’ları gibi ek korumalar önerilir. MCP Client (client.mjs / agent.mjs içindeki client rolü) MCP Server’ı stdio üzerinden başlatıp araçları çağıran yürütme katmanı olarak çalıştı, yani veri tabanına doğrudan bağlanmadı. Agent (agent.mjs – Node.js orkestratörü) orkestratör rolüyle kullanıcı sorusunu aldı, MCP Server üzerindeki “query” aracını çağırarak sonucu topladı ve en sonda bu sonucu Oracle Generative AI (LLM)’e verip özet/yorum ürettirdi. Bu nedenle bu versiyonun “agentic” tarafı, güvenli tool kullanımıyla execute -> observe akışını ve LLM’in sonuç yorumlamasını göstermektedir.
Sarav Asiye Yiğit 27 – 28 – 29 Aralık 2025






Yorumunuzu Bırakın